It's probably best not to consider the legal implications too far. Before even getting to anything as complicated as Heroes testifying in court, when you look at it from a legal perspective the Heroes are the ones who are committing crimes. Unless the government forms some kind of sanctioned organisation which Heroes can sign up for, any time they fight crime they're essentially vigilantes. I guess you just have to foil whatever plan the supervillains carry out and hope they are already wanted for other crimes, so you can just drop them off at a police station without having to testify.