Flange gaskets are used to create a static seal between two flanges faces, at various operating conditions, with varied pressure and temperature ratings.
A gaskets fills the microscopic spaces and irregularities of the flange faces, and then it forms a seal that is designed to keep liquids and gases. Correct installation of damage-free gaskets and demage-free flange faces is a requirement for a leak-free flange connection.
If it would be technically possible, in order to manufacture flanges perfectly flat and smooth, and perfectly compatible with one another under all operating conditions, a gasket would not be necessary. But in normal practice it is not possible, because flange connections under ANY circumstances should be made. Small impurities and a small bit of dirt, is in practice not be avoided and therefore it is necessary to use a gasket.