Krakatau erupted partly because it is located in an area with high volcanic activity in Indonesia, according to Wikipedia, and partly because of the structure of the island itself. Smaller eruptions, that started about two months earlier, created fissures in the sides of the volcano, states the Australian Bureau of Meteorology. The fissures split open, and sea water poured into the crater of magma, causing a huge explosion.
According to Argonne National Laboratory, volcanoes erupt when rock under the planet’s crust melts, becoming magma. Magma’s lower density causes it to rise to the surface. If magma contains water or gasses, it will expand into steam as soon as it reaches the surface of the earth, resulting in a violent volcanic eruption. In the case of Krakatau the magma had already reached the surface of the planet but had been contained within the land mass until August 26, 1883. When the sea water reached the magma, the explosion destroyed two-thirds of the island.
The Krakatau explosion was heard in Australia, 3500 km away, and was loudest sound in recorded history. It started a tsunami that killed 36,000 people on nearby coastlines. One thousand more people died from superheated volcanic ash that traveled across the ocean.