It depends on 2 things;
Classification of drywall by your local jurisdiction: flammable material or not
Water heater vent pipe type: single wall or double wall
Single wall vent pipe entire run must be fully exposed and accessible, no sections can be concealed. So if your water heater’s vent pipe is a single wall type and enters the ceiling it must be replaced with double wall (B-vent) before the ceiling and inside the ceiling / wall.
If you already have a double wall vent pipe installed; the minimum distance to combustible materials is 6”. In case your local building department considers drywall as a combustible material you’d have to install special metal collar that ensures that clearance at the ceiling penetration and you could seal any remaining gaps between the collar and surrounding it drywall.
If there are no drywall – water heater vent pipe clearance restrictions in your area you could seal the gap using drywall compound or high temperature caulking which must be fire rated in multifamily buildings.