It doesn't, except when the rain is associated with sufficient convective vertical development in the coud formation to form Cumulo nimbus with it's associated lightning (which is the cause of the thunder)...
Thunder is the sound produced by lightning rapidly heating and exciting the motion of molecules of air through which it travels. Light travels much faster than sound so lightning is seen before it is heard as thunder.