try turning of "mouse click" targeting, it used to happen to me, it seems my use of mouse flying and the use of mouse button 4 and 5 for weapons fire, meant that sometimes I was accidently coming off of mouse button 2 during my frantic mouse clicking and the UI would see button 1 for click targeting. If a ship fell under the intermittent mouse arrow as this happened, I'd lose my target.
I don't know if it's related, but I often find I can't target incoming heavy torps. I have target closest set to T, but when I hit it, it targets a ship (often not even the closest). Other times, I can't target exposed enemies unless I cycle through all of them one at a time. Clicking sometimes doesn't work and is often difficult, especially in crowds (such as when you're surrounded by targs).
Well good to know I'm not the only one with this...I always figured it was just some weirdness in the settings. I used to have it set to assist my target when I fire weapons, but if I were to target an enemy and try to fire, I would find myself targeting an ally of mine who was targeted by the enemy I initially tried to shoot at. I've since turned that option off, but every ones in a while I end up randomly switching targets, and it seems to happen in spurts. For example; it might happen 3-4 times inside one minute, and then not happen again for weeks, then it happens again 3-4 times inside a minute.
also blind heals will change your targets as well in combat by targeting whomever just got your heal and then throwing your attacking back onto the nearest enemy.
You can fix that though by turning off the "auto assist on attack" thing in options. Think that is the name.
For some reason, STO has a silly way of implementing assist. In most games, you target whatever you want and, when using a hostile move on a friendly target or a friendly move on a hostile target, it'll use that target's target. STO, for some silly reason, causes you to switch your target to the target's target, then use the move.
It is poor implementation, one they didn't use in CoX. Not sure why they went this route, but, well, the sooner you turn off the auto-assist thing, the better.
A new feature cryptic could be able to implement would be dual targeting where you can target up to 2 targets while only able to engage one. Sorta like the target and focus system mainly applied to wow or other mmorpg games you could have a combat target and a support target. This is believe would negate some issues of auto targeting and this feature would deffently help out some in PVP where misdirected heals happen the most especially if you want to keep attacking in an escort but you just saw your healing cruiser friend get snb and is about to die and you want to slap like sci-team on him or something so he could recover all the while not waisting your precious attack buffs as an EX. Or implement the option to turn off "auto casting" for target able abillities making you have to manually target with abilities like HE, ES, or any of the 3 "team" abilities. But the current fix would be to disable assist and/or auto fire.