The distance at which two commercial aircrafts have to be apart will vary depending on the different phases of flight and the altitude at which the plane is. The vertical and horizontal distance will also be different, and the rules might differ between regions.
A commercial aircraft that is flying below 29,000 feet will need to maintain a vertical separation of at least 1000 feet. If they are flying higher than this, then the distance will increase to 2000 feet, unless they are in an airspace where Reduced Vertical Separation Minimum applies. This allows aircrafts to fly with a vertical distance of 1000 feet between them.
Aircrafts can cause something that is called wake turbulence, which can affect other aircrafts that are flying the same track at the same altitude. So, the horizontal separation will need to be much greater than the vertical separation. In a controlled airspace, the required horizontal distance between aircrafts is the same altitude as 5 nautical miles, which works out to be slightly more than 9 kilometers.
On departure, air traffic controllers will need to place aircrafts much closer to each other than they would be during flight. So, within the terminal area air space, horizontal separation decreases to 3 nautical miles.