If you were to eat a chili pepper, it would make your tongue sting causing that feeling of your mouth being on fire. Chilies contain a substance called "capsaicin" that causes that burning/stinging feeling in your mouth.
Milk contains a substance called "casein". Casein is a fat-loving compound that binds with the spicy capsaicin oil, in chilies, and then washes it away.
Drinking water won't help as much as milk will, though. Since capsaicin is an oil, and water and oil don't mix, water won't help you much.
Water based liquids will actually spread the capsaicin oil around your mouth, instead of reducing the burn.