If Islam opposes idol worship, why do Muslims pray to a square structure?
The simple cube-shaped stone building located in Makkah is called the Ka‘bah or the Sacred House. It is the point toward which Muslims face when they pray. Although Muslims face the direction of Ka‘bah during prayer, they do not worship it. Muslims worship and pray only to God.
The Ka‘bah was built by the prophet Abraham and his son Ishmael in response to God's command over 4,000 years ago. Abraham consecrated the House for the worship of the one true God and invited all of humanity to visit it for that purpose. Even today Muslims who are physically and financially able are required to make a pilgrimage to it once in a lifetime. The Ka‘bah has remained at the center of a continuous tradition of worship and devotion up to the present day, symbolic of permanence, constancy and renewal.
There were periods in human history during which mankind deviated from the monotheism taught by God's prophets. Before the advent of Muhammad, religion among the Arabs had degenerated into polytheism and paganism, and Makkah was completely submerged in idolatry; some 360 idols had been placed in and around the Ka‘bah to be worshipped there along with God. Prophet Muhammad was sent to restore to mankind the pure monotheism taught by all the messengers of God and reinstate the worship of Him alone. This he accomplished, and the Ka‘bah was finally cleared of all manmade deities.
Among the ancient religious rites particular to the Ka‘bah is walking around it. This suggests the integrating and unifying power of monotheism in human life and how a Muslim's existence should revolve around a pure devotion to God. The Ka‘bah symbolizes the unity of all true religion, the brotherhood of all the prophets, and the essential consistency of their message.
When Muslims pray facing toward this single central point, they are reminded of their common purpose and long-term goal. Even when standing directly before the Ka‘bah in prayer, one is not to look at it but rather at the ground before him. The spiritual focus is on God alone and never upon any created object.