A unit is not allowed to end their move closer than 1" to another unit, friend or foe, or impassable terrain (as described in the Battlefield Terrain chapter). If pivoting the unit on the spot would cause you to come into base contact with another unit or impassable terrain, you must move your model back so that it is still 1" away from these after your pivot. If your model cannot be moved back because it is between two units or pieces of impassable terrain, you should, if possible, move the other unit back so the pivot can be performed. Note that units that are engaged in close combat may never be moved back in this way. On the off chance that neither unit can be moved back, the pivot may not be made.
This rule does not apply to charge moves, as the whole point of charging is to get a unit into base contact with an enemy. Occasionally, a unit will have approached to within 1" of a unit it did not charge as the result of moving into contact with a unit it did charge. This is perfectly acceptable, although players may wish to nudge the units further apart to maintain a suitable degree of clarity.