Pressure-controlled polytypism in hydrous layered materials