but why does this lub-dub sound occur?
During ventricular systole or contraction the pressure in the ventricles rises and closes the AV valves, preventing blood from returning to the atria. The pressure forces opens the semilunar valves of the aorta and pulmonary artery and the blood enters these vessels. The closing of the AV valves during ventricular systole produces the first heart sound, described as 'lub'.
Ventricular systole is followed by ventricular diastole (relaxation). The high pressure developed in the aorta and pulmonary artery tends to force some blood back towards the ventricles and this closes the semilunar valves of the aorta and pulmonary artery. Hence backflow into the heart is prevented. The closing of the valves causes the second heart sound, 'dub'.