Will I get in trouble for sitting in on a college lecture if I'm not a student there?

Basically the title. Will I be punished for listening to the class as a high school student?

No, as long as you understand that you are just a visitor and you let security know that you are listening to a lecture.

Right. There’s a process in place; it’s your responsibility to find out what that process is.

Contact admissions, let them know what you would like to do. They’ll be happy to accommodate you.

But I would warn you: there’s something like 2 weeks until finals begin on many college campuses. Not all profs may be open to the distraction of a visitor so late in the semester.