During their stay in Lothlórien
Although we're not given a great amount of insight into Legolas and Gimli's burgeoning friendship, this is clearly the time it begins (emphasis mine):
Legolas was away much among the Galadhrim, and after the first night he did not sleep with the other companions, though he returned to eat and talk with them. Often he took Gimli with him when he went abroad in the land, and the others wondered at this change.
Fellowship of the Ring Book II Chapter 7: "The Mirror of Galadriel"
The Company was arranged in this way: Aragorn, Frodo, and Sam were in one boat; Boromir, Merry, and Pippin in another; and in the third were Legolas and Gimli, who had now become fast friends.
Fellowship of the Ring Book II Chapter 8: "Farewell to Lórien"