So I plugged in the same keyboard today and magically it worked...I guess it must be a loose connection on the usb?

It could be ... it's a mystery! Maybe check the inside of the USB socket (and plug) for any detritus? although that'd have to be pretty big to cause electrical continuity issues!

a year later

I will add to this that I frequently have the USB MIDI fail to work on boot up, maybe one time out of ten, randomly it seems.

What image are you running ? This was definitely pathologic on some image versions (v0.3.8 through 0.3.8b), but it should be fixed now.