Why are chess.com opening names and notations seemingly mismatched? I often see something like the above when playing chess online. When I played Ruy Lopez and my opponent played Classical Variation, but I transposed us to Four Knights Game Spanish Variation, I had castled in between the Classical move and the transposition (Move 4).

It seems the reason the opening name says "5. O-O" because it one of the openings where the order of moves doesn't matter. But is this a bug in chess.com or intentional for the opening name to be mismatched with the move numbers?
I think this is intentional. The opening name alludes to the position reached, not the route taken to get there. The principal move order to reach this position is to start with the classical variation of the Spanish variation of the four knights game and play 5. O-O. 

It wouldn't make sense to say Four Knights Game: Spanish Variation, Classical Variation, 4. O-O because if you had reached it from that route then you wouldn't have castled on move 4. While it would make sense to describe it as a Ruy Lopez with 4. O-O, it would be undesirable to list the same position under two different openings.