The first sentence is correct.
In the first sentence, over is an adjective. It makes sense:
The class was over when we arrived.
The class was finished when we arrived.
The class was crammed with students when we arrived.
The second sentence doesn’t make sense because over isn’t a verb. You cannot over something. And you especially cannot use it in the passive structure (had been over).
You could use the past perfect instead: The class had (already) finished when we arrived.
Or, you could use over as an adjective in this structure: The class had been over for 20 minutes when we arrived.
Special thanks to Arnel Nisbet for help, (My dear friend and director of English School.)