The shape of Ka'ba has been taught to the Prophets who raised the walls of it by order from Allah (SWT). In the Hadeeth: The Ka'ba is beneath al-Bayt Al-Ma'mour in the sky, which is based on four Corners. Bayt Al-Ma'mour is beneath The A'rsh which is based also on four corners (Subhanallah, WAL Hamdulillah, wala elaha illallah, wallahu Akbar).
Ka'ba is the center of the whole world and all Muslims have to face its direction while praying or slaughtering an animal or burying a dead body. It's shape makes people in all the sides of the earth able to face its direction.