for example, I use my virizion to fight with registeel, I use "close combat" and he use flash cannon. I beat him first and in next round I use my flash cannon to cobalion who was replaced and he beat me first. WHY?
This relies upon your Pokémon's speed. All Pokémon have a speed stat just like they have any other stats. Speed determines which Pokemon move first in a battle. The Pokemon with the highest speed moves first. So let's take for instance your Virizion vs. Registeel example. Registeel's base speed is 50, which means at level 100 (most Pokemon are level 100 in competitive formats) the speed stat will be 136. Virizion's base speed is 108, so at level 100 it will be 252. 252 is higher than 136, meaning Virizion will move first.
Now after that, you say that Cobalion moves first. Cobalion's base speed is also 108. So, assuming none of them have any EVs in speed or speed-raising natures (explained in the links below) Cobalion's speed stat will be the same at 252. This results in a speed tie.
If the opponent Pokemon has the same speed as you, there is a 50/50 chance of who will go first, unless one of the Pokemon uses a priority move, or changes form to have higher speed.
(Source for quote)
Your Pokémon's speed can be modified with things like Effort Values (EVs), Natures, and Individual Values (IVs).
If the Cobalion in this example had a Jolly nature for instance (Which raises the speed stat by 10%) Cobalion would have 277 speed, therefore always outspeeding your Virizion, which has 252 speed.
There are also some special situations involving speed, like Priority.
Every Pokemon move has a set Priority. Most attacking moves have a priority of 0, meaning that the Pokemon's speed stat decides who goes first in a battle. Some moves have a higher priority. Let's say for instance you ordered a Diggersby to use Quick Attack. Quick Attack has +1 priority, which means it will move faster than your Pokemon using Stone Edge. Because Stone Edge has 0 priority. You can research all the specifics of priority here.
Another special move is Trick Room. Trick Room means that for five turns, the Pokemon with the lowest speed stat will move first. (Trick Room has a priority of -7 speed by the way, meaning it will always move last.) Let's use your example again.
Registeel's speed without any modifiers is 136, right? Virizions speed without any modifiers is 252. Normally, Virizion would always move faster than Registeel. However, under the influence of Trick Room, Registeel would move first because it's speed stat is lower than Virizion's.
Trick Room reverses the move order within each priority bracket so that Pokémon with a lower Speed stat attack first, while those with a higher Speed stat will attack last.
Some other modifiers are moves and held items.
A Choice Scarf boosts the holder's speed by 50%, but it can only use the first move it selects. Basically, it takes your Pokemon's speed, and doubles it while in battle. It's explained a little more here.
Moves can also have a big impact on speed. Moves that raise your Pokemon's speed in stages are actually multiplying your Pokemon's speed by a specific fraction/decimal. For example, if you use the move Rapid Spin, it will raise your Pokemon's speed by 1 stage. Which means it takes your Pokemon's speed and multiplies it by 3/2 (three halves.) There are specific multipliers for each stage, positive and negative. It's explained more here.
The examples and rules explained here apply to all Pokemon.