I have only played two PvP battles in any Pokemon game my entire life. Once when I was 10 and the second time a few weeks ago. It was pretty miserable the second time as the opposing player began every single move by switching his Pokemon. Somehow, no matter which Pokemon he used or which ones I used, he was always given the ability to move first after switching. This meant he was constantly switching in and out to get type advantage or to prevent KO's which turned it into an un-fun game of whack-a-mole. He also ran out the clock on almost every move because he couldn't decide what to do. In spite of all that I won but it was such an un-fun experience that I don't want to repeat it.
Your pokemon get a move on the switch, which the opponent doesn't get. If neither side switches, the faster pokemon will go first (for true speed ties, it's 50/50).
There are also priority moves, which allow a slow pokemon to go first if the enemy does not also use a priority move, some abilities that give priority to certain move types, and a move that flips who goes first for a while (trick room). There are also moves that boost speed until said pokemon is beaten/switches (like dragon dance) and an item that gives you a speed boost but doesn't let you change what moves you make until you switch pokemon (choice scarf).
Some moves even have negative priority and will in most cases go last despite speed.
Which pokemon acts first is actually significant to PvP strategy, and there are some pretty tough/mechanically complex tradeoffs to be made when deciding what pokemon, items, and moves to use when it comes to speed.
Let's give a basic example:
I have a physically-oriented fire type pokemon in. You switch to Gyarados. Since I don't have an electric move and my attack stat just got lowered by your ability, I switch out. On the turn I switch out, you use dragon dance.
If I switch in an electric type that isn't either very fast naturally or choice-scarfed, you can instantly kill it using a water/flying pokemon that takes FOUR times normal damage to electric moves, because your Gyarados will get to move first and use either Earthquake (electric weak to ground) or waterfall (electric doesn't resist and non-tanky electric pokemon will die to a +1 waterfall from a Gyarados). This opens my entire team to getting smashed unless I have an amazing physical wall.
But what if I had a choice scarf? I could then simply tbolt your Gyarados and kill it instantly, since I move first as long as my electric type's base speed is faster. But knowing this, you might switch to a ground pokemon, and since choice-scarf move locks me I literally can't do damage so you can freely choose a non-ground move to hit a predicted switch or just set up again. Unless I predict this and also switch at the same time you switched to the ground type.
Or instead of using dragon dance, you might guess that I am going to bring in an electric pokemon in advance and just immediately use earthquake rather than dragon dance, which can easily kill many electric types w/o the boost. But! I might not switch in an electric type. I might switch in a skarmory to whirlwind you out, or a physically bulky water with haze, or even my own Gyarados (which doesn't have dragon dance and is instead a choice variant or maybe a roar variant). Maybe I got stealth rock up, so your Gyarados already lost 75% of its health and is more vulnerable to priority moves. Maybe I instead bring in a grass type with spore, put it to sleep, and start using everyone's favorite sub-seed setup from there.
~~~
And the above is just a small part of a single battle with specific pokemon, there are lots of interactions. So much to consider that is just never relevant in SP runs.