What I expected to happen was...:
You would sleep in the bed like normal.
What actually happened was...:
You sleep in the bed, while still in the minecart, causing the glitch and then waking up in the minecart.
Steps to reproduce:
1. Get in a minecart that is going in a straight line past a bed.
2. Get in to the bed while driving past it.