Standard approach used to be to drag any friendly locked up targets down to the next row of targets; and only leave the targets you should be shooting on the first row.
Or in other words, while targetting automatically organises the locked targets on a single row by default, that isn’t the only way to have them organised and you can drag your locked targets around, including to new rows.
So when you lock up a friendly, just drag the target down (or up if you have your targets low on your screen), so you never accidentally select them and then shoot them. That way, only activate guns/missiles/rockets/etc. on enemy targets on one line and reps or friendlies that are on another line.