Wood Trim that has Come Loose
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.