When the prophet was 35 years old, heavy Rainfalls and floods damaged the kaaba and so the Quraysh started rebuilding it as there was a fear of the kaaba collapsing, but when there was the question that who would place the Black stone, an elder suggested that the first person to enter the mosque next morning would do it. The prophet happened to be the first person and so what he did was that he made the leaders of all the tribes raise the stone to the level where it was to be deposited and then he himself placed it, and thats how he used his wisdom to avoid bloodshed