I have a thin strip of wood trim on the inside of a bedroom door frame that needs repairing (it's loose). What should I try first?
If the piece has been attached to the wall with fasteners try tapping it back in place and adding 1 or 2 6 penny finish nails. If that isn't possible than try using wood glue by applying glue to each of the damaged pieces. Bring the pieces together and if possible clamp the piece in place while the glue is drying and/or fasten to wall with finish nails. Wipe up any oozed-out glue with a damp rag before it dries. After a few hours lightly sand and paint.
My best suggestion from personal experience and opinion, is to stay away from adhesives. Mechanical fasteners (nearly) always have a method of removal that doesn't destroy the things it's fastening. You can pull a common nail, back out a screw, or punch through a finish screw.
In my house I've had similar things happen, and it's usually due to the wood expanding or contracting in such a way that the finish nail has pulled through the wood and is no longer mechanically squeezing the top piece to the substrate.
A few (2-3) well placed, ringed finish nails would go a long way. I prefer "panel nails" for this kind of work, so long as they aren't too long. Their ringed shanks tend to hold well.
If you can locate studs or other timber behind your trim, I especially like specialty "finishing screws" with counter threaded shanks near the head to minimize that "swollen" area around the head.
Based on your description it sounds like it's the door stop molding. It's a thin piece of trim that goes around the sides and top inside of the door frame that the door presses against when closed so it doesn't swing all the way through. Common size is about 1-1/4" wide by 3/8 to 1/2" thick.
It's common for these to come loose over time especially if it's installed so that the door hits it when it's latched closed. Also if someone falls against it or kicks the door from the inside when closed.
Close the door so it latches, press the trim back in place and hold it. Make sure the door continues to open, close and latch properly. Should be about a 1/16" gap between the closed door and door stop. Take a pencil and mark the door jamb (the wider board that the door stop sits on) where the door stop trim rests up against it. That way you won't push it too forward to interfere with the latch or leave it too far back to create a gap.
Grab a hammer and some 2d finish nails (or 1" long 16 or 18 gauge nails if you have a finish or brad nailer or smallest size it takes around that size) and use them to attach the trim to the door jamb. You don't need very big or long nails. The only thing you're nailing into is the 3/4" thick door jamb behind the door stop.