Well it's the same reason everyone stands when the President walks into a room. It's more than likely stemming from a root of dictatorship or monarchy where standing essentially "hails" the leader and showing that leader your loyalty. So instead of us Hailing the flag like we're Nazis, we put our hand over our heart instead, also to show our faith in God as a Christian-founded nation