Overwatch 1 os a team of 6. At launch, there were no restrictions. You could be and switch to any hero or role at anytime. That includes duplicates. Want to have 6 of the same tank? Go for it.
Eventually duplicate heroes was decided too hard to balance. They stopped duplicate heroes. Now you could switch to any hero or role at any time, but it must not be a hero already on your team.
As they added more shield tanks, it became harder to balance around. "GOATS" (I have no idea what the acronym means) became "meta" which was 3 tanks, 3 supports.
Eventually Blizzard gave up on balancing GOATS and forced role queue. 2 tanks, 2 dps, 2 supports. The role you start with is the role you had to stay in. You could switch to any hero in that role at any time so long as it wasn't what the other person was on.
Games were still sluggish, and Blizzard, with Overwatch 2 is making a lot of changes to speed the game up. Particularly, they're reducing a lot of CC abilities and eliminating 1 tank role. Games are now 5v5 with 1 tank, 2 dps, and 2 support