I have a couple of suggestions that may fix this. Please note that these suggestions mostly apply to PVE servers, where PVP should be optional and consensual, in my opinion.
I've accidently toggled my PVP flag as well by right clicking on my userpic a couple of times. Attempting to get some game time after a 12 hour work shift will do that.
How about a 10 second timer warning like they use when entering enemy territory, that gives you time to cancel toggling PVP or let it activate?
I would also like to see PVP options available under Combat on the Preferences tab, such as for the suggestion above.
Currently, griefers and gankers are using the PVE areas on Tatooine (instead of the PVP areas) to take advantage of the Auto Target Closest Enemy that most people have enabled in their preferences for PVE. If you are still button mashing when your PVE target dies, then it will grab the PVP target as the next one and flag you for PVP. Next thing you know you got a couple of level 50 players jump out of stealth and slaughter your level 30 butt in 5 seconds or less, while their buddies guard your nearest respawn point to get you again and again. At least that is the method they appear to be using on my server anyway.
Perhaps a Manual PVP option can be selected in Preferences, so that if it does Auto Target a PVP target instead of a PVE target, then the next attack does not go through (similar to attemptin to launch an attack on a friendly target) unless the PVP flag is manually activated.
Similarly, attempting to heal or cleanse a friendly target who is flagged for PVP does the same (lots of people also acquire PVP flags when grouping up currently as well).
The suggested Manual PVP option to be added to Combat Preferences may work well with the suggested PVP Timer option as well.