Your flashing will need to be fastened in place with something. I made 3 sketches the illustrate hopefully on of the ways to reset your flashing back in place.
The first of three labeled, "Not good" ids the least desirable way to set flashing to a wall but it is done everywhere. It is simply a piece of metal liad to the wall and held in place with masonry nails and caulked. Hot and cold weather will make the caulk fail when the metal buckles between nails.
The second is "good", the flashing is turned into a deep cut mortar joint (about 1")and nails are placed so the head of the nail laps over the bend edge (about 3/4") to hold the flashing in place. With the rigidity created by the bent corner and the nail not penetrating the flashing, the metal can move more freely when the temps change. In both cases mentioned already I have seen nails rust or fall out or both, in time.
The third, to me is the best, it has its down side but there are no nails to rust. I have seen this on old roofs I helped redo and was impressed how well it worked, using wood shims. It is the same procedure as the second sketch but no nails are used. The technique is, 2 cedar shims are used, in each spot, cut to allow the whole shim to fit in the joint with the metal. They are laid one on top of the other, points together, and driven so they snug in place as they slide by each other with in the joint. Needless to say the shims need to be cut to 3/4" wide to fit behind the surface of the brick or drive wider ones in then cut off the excess an caulk the joint, covering the shim, actually that is much simpler.
The caulk to use is made by many manufacturers, OSI, Geocel, Locktite and others, all have a caulk that is rated to do what you need. The big box stores will have them on hand, or even your local small hardware stores will carry the line of caulk you need. It is just roofing caulk, see that it has a warranty long enough to last the lifetime of your roof.