Nystatin functions by binding to ergosterol, a key component of the fungal cell membrane. This binding action disrupts the cell membrane, leading to the leakage of cellular contents and ultimately causing the death of the fungal cell. Unlike some other antifungal medications, nystatin is not absorbed into the bloodstream when used topically or vaginally, making it a good option for localized infections.