It originated from shihohai (Prayer to the Four Quarters, Japanese imperial New Year's ceremony), spread across ordinary people as a present form and came to be the custom where people pray to hatsu hinode.
四方拝という天皇の元旦の儀式が始まりで、それが庶民の間に現在の形で広まり、初日の出を拝むという習慣になった。