Cabin bed attached to wall on two sides
For any load bearing construction, you want wood-on-wood carrying the load, rather than lateral bolts carrying a shearing load.  Give your bed some legs.

You can still screw it to the wall, but the load should be going from the wood frame, to wood legs, to floor.