How do I repair this soffit flashing thing?
Its just trim molding, to hide the cut edge of the soffit where it abuts the wall.

It should be re-attached for both appearance and critter protection.  You can add some foam insulation, which will help seal the edge.

A bead of exterior caulk, then the molding, then another bead if there are any gaps in the molding-to-wall or molding-to-soffit,

Use 1" to 1 1/2" hot-dipped galvanized 4d finishing nails and try to hit structure underneath.  If you are a tool hound, this would be a good time to get a small air compressor and an 18 ga finish nailer.  Tell your wife you can inflate her tires and the kids basketballs/footballs.  I've expanded from 18ga nailer to 15 ga nailer, crown stapler, 16d framing nailer and strip flooring nailer, all with the same pancake compressor.