The sun appears to rise in the east and set in the west because of the way the Earth rotates on its axis.
The Earth rotates in a counterclockwise direction as viewed from above the North Pole, and this causes the sun to appear to move across the sky in a westward direction. When the sun is on the opposite side of the Earth, it appears to rise in the east because the Earth has rotated to the point where that part of the sky is now in the east.
It's important to note that the sun doesn't actually rise and set. It's the Earth's rotation that causes the sun to appear to move across the sky. The sun is always in the same place, but from our perspective on the surface of the Earth, it appears to move because we are moving with the Earth as it rotates.