Often that is the best response to what other firms are doing. In a simple Hotelling game with homogenous goods and perfect information, assuming two competitors trying to locate themselves on a line segment (e.g. some street), where both companies compete for customers that will always choose the closest business, it is Nash equilibrium for both companies to locate themselves next to each other in the middle of the line segment.
This is because if a one company occupies the center of the line segment the other company will always get less customers if it also does not position itself exactly in the center. So best response of both firms to what the other firm is doing is to both locate in the center to maximize sales.
Whether this occurs depends on whole host of factors. For example, when the consumer transportation costs are very high firms will have more incentive to locate further apart to 'soften' the price competition between them. Next, differentiation plays role. Generally, the more the product is differentiated the less incentive there is to locate exactly next to the competitor. Geometry of the space makes difference (e.g. line, circle, grid). Some geometries make encourage firms to locate next to each other why others might not.
These are just examples, because of multiple possible geometries of space and ways firms can compete there are numerous variants of Hotelling game. In different versions of the game different factors may play significant role in what the equilibrium(ia) is(are). You can have look at Tadelis Game Theory: An Introduction or Fudenberg and Tirole Game Theory, for some examples of various Hotelling games and see when they produce equilibria where players locate next to each other and when not.