This will depend on jurisdiction. In Germany, this is regulated in the German civil code, the Bürgerliches Gesetzbuch, mostly in § 275 Ausschluss der Leistungspflicht:
- If the service equired in a contract is objectively impossible, the duty is voided. A typical example would be a purchase contract for a specific item, which was destroyed before it could be delivered.
- If the service required would mean a "disproportionate" effort for the party required to provide it, that party has a right to refuse.
However, if either of these situations occurs, the aggrieved party has a right to:
- get back their part of the deal, e.g. be refunded any payments (§326 BGB), and
- receive appropriate indemnification - both for the value of the service or good they did not receive, and to offset any costs they incurred because they relied on receiving the service or good. However, indemnification only applies if the problems were a fault of the providing party (§280 BGB).
Addressing your examples:
I know of a person who had a contract for a job that started on x
start date and y end date and was paid per hour for 38 hour work week.
After y end date passed the boss contacted the person saying he hadn't
fulfilled his end of the end of deal as he still had 30 minutes of
work left to do (presumably this was because he didn't make up for
some time he took off when sick and didn't get sick days). Could the
boss sue for the remaining 30 minutes?
If the person missed work due to being sick, they would have to make up for it. So, unless there is some agreement or legal rule on how to handle sick time (which is usually the case for regular employees), the boss could indeed claim compensation for the missing 30 minutes. They could claim 30 minutes' pay, but not any additional damages (because it is not the employees fault they got sick).
Also, as in this question, if a formal contract was agreed between a
dog owner Bob and a dog walker Alice, that Alice would walk the dog
each day for a few weeks for a set amount of pay, what would happen if
Alice became sick or the dog wasn't able to go for a walk and nothing
regarding these circumstances was written into the contract?
If Alice became sick, then again, Alice would be allowed to not walk the dog, and would not receive pay for that time. Again, no indemnification, because it was not Alice's fault (unless she was to blame for being sick, e.g. because she drank too much alcohol). If the dog wasn't able to go for a walk for an unrelated reason (e.g. the dog being sick), Alice would have a right to receive pay, because she held up her part of the deal (being available to walk the dog).
What if someone signed a contract that they would be paid to clean a
building but the building burned down before they could do it?
Again, the contract would be effectively void, and no payment due. Also no indemnification, unless the owner burned down the building on purpose.