The heart itself is not anchored to the diaphragm. The heart is enclosed in a double-walled sac called the pericardium. The fibrous outer layer of the pericardium anchors the heart to the sternum, the diaphragm, and the large blood vessels. The heart needs to be anchored in place to keep it from moving around in response to movements of the person and its own muscular contractions.
The attachments to the diaphragm also act to assist the heart to move appropriately in response to motions of the diaphragm. As the diaphragm moves up and down during breathing the heart is moved by the attachments to avoid being compressed, describes a study published in IEEE Transactions on Medical Imaging.
Teach Me Anatomy describes the pericardium as being like the peel surrounding the orange. It acts to protect and contain the heart. Without the outer layer of the pericardium anchoring the heart to surrounding structures the heart would slosh around and compress the lungs with every step the heart's owner took, making it difficult to breathe well. With more extreme motions an un-anchored heart could possibly move far enough and fast enough to rupture the attachment to the aorta, which might prove fatal.