How do I tag enemies in Fallout 4?

This is the "track targets" effect that is described on the Recon Scope weapon mods, under the "Sights" modifications of weapons. By targeting the enemy through the recon scope, the red diamond will appear above them.

As pointed out by Yorik, the Recon Sensor modification for power armor helmets will have the same effect and mark enemies when aiming down the sights of any gun. More information, including materials needed for this mod, can be seen here.

The diamond seems to persist above the enemy until it is killed, meaning you can track the enemies with the recon scope gun and switch to another.