Function of the spermaceti organ
The principal function of spermaceti and the associated structures in a sperm whale head, is echolocation. The composition of spermaceti suggests that it functions as an acoustical transducer, helping to focus the powerful sound waves used for echolocation. These sound waves likely do not actually stun squids, but they do help sperm whales to find and pursue squids in deep, dark waters.  

An echolocation click is formed at the tip of sperm whale's nose, where it is directed backwards, through the spermaceti, toward the sperm whales brain. It then is reflected off an air sac on the sperm whale skull, and redirected forward through a series of lenses before it moves into the water. Check out an illustration of this in the Møhl et al 2003 paper: https://pdfs.semanticscholar.org/88d4/271e9f7490c1173234a2445cf8ddf92fd51f.pdf 

The complicated anatomy in a sperm whale's head seems to be directly evolved for echolocation. 

Sources: 
Karol, R., Litchfield, C., Caldwell, D.K. et al. Mar. Biol. (1978) 47: 115. https://doi.org/10.1007/BF00395632

Møhl, B., Wahlberg, M., Madsen, P. T., Heerfordt, A., &amp; Lund, A. (2003). The monopulsed nature of sperm whale clicks. The Journal of the Acoustical Society of America, 114(2), 1143-1154.