Can I use two 2x4's to replace 4x4 posts in a loft bed?
2 2x4s are not square, if that matters (3 x 3.5). They will be plenty strong as assembled posts.

Try a traditional lumber yard, they will have untreated pine.  Cedar may also be an option. 

Your structure would be better supported if you shortened 1 of the 2 paired 2x4s at each corner and made a jack-king stud arrangement like a door frame and header.  The main tenant of construction is to bear the weight with structural components and only use fasteners to keep the structure in place, not to bear the load (in shear).

You are, in effect, making a small deck.  You should attach the rear 2x8 2x6 to each wall stud.  A 4" #10 decking screw would not be too small .

The front and rear members are, in effect, beams and should be 2x8s.  The joists running perpendicular to the beam should be 2x6 2x4s hung with joist brackets.