When soil is saturated with water, like in coastal areas, water is settled between the soil particles. Think of marbles in a glass of water: the marbles are the sand particles, the water is in between the marbles.
The soil particles are in contact with each other, and this contact gives the soil its strength.
When the earth shakes during an earthquake, the soil particles move closer together, a denser solid if formed, the water can’t move out of the way quickly enough and pressure builds. This pressure causes the contacts between soil particles to break. The soil is suspended in the water and it behaves like water. This is liquefaction.
It’s a temporary condition. When the water can drain, the pressure is relieved, particle contacts are reformed in a process called reconsolidation.
Think of walking on the sand on the beach by the water. The soil is firm, you step on the sand, the water comes to the surface. In an earthquake, the water can’t get to the surface and instead, the pressure builds, causing the breakdown of contacts between soil particles.