Lub-dub sound is due to
the valves opening and closing
The distinctive lub-dub sound of the heart is because of the opening and closing of the valves of the heart. The valves of the heart prevent back-flow of blood when the heart contracts.
For example, the valves present in between the atria and the ventricles open to let blood into the ventricles from the atria. They are closed when the ventricles contract to prevent backflow of blood into the atria. Similarly, the semilunar valves prevent the backflow of blood from the aorta and the pulmonary artery to the left and right ventricle respectively.