Lavatories (airplane toilets) can be inoperative for many reasons, they could get blocked by someone vomiting in the sink, or by throwing tissues or other objects in either the sink or the toilet seat. Sometimes, when a waste tank is full, or there's a problem in the sensor of the tank giving a wrong signal, all flushes connected to that tank will not work, this happens in modern aircrafts.
If a sink or a flush are not working, the toilet has to be blocked by the crew/maintenance or stuff would be piling up!
For each aircraft type (usually depending on the passenger load and toilet locations), there is a limit of toilets that can be inoperative while airborne before the flight has to land at the nearest airport.
This depends on the model and airline's policy. But a rule of thumb is: half of the toilets in each zone should be operative. Otherwise the flight has to land if this happened during the flight. If the flight is on ground and for example all toilets in business class are inoperative, the plane can take off but no passengers should be in that class.
In some airlines, if all the toilets at the front are inoperative, even if there are no passengers, the plane has to land if it's flying or will not be able to take off if it's on ground because pilots are only allowed to use toilets in the front.