Defender is a static ability defined in CR 702.3a: 'A creature with defender can't attack.' That's the entirety of what defender does — it restricts the creature from being declared as an attacker. It says nothing whatsoever about blocking.
Blocking is governed by CR 509.1, which lists the requirements and restrictions for declaring blockers. None of those default rules exclude creatures with defender from blocking. Since defender's text only mentions attacking, a creature with defender is completely free to block at any time, regardless of whether it also gains the ability to attack.
The second part of your question — gaining the ability to attack — is also handled cleanly by the rules. Effects that grant 'this creature can attack as though it didn't have defender' (CR 702.3b) simply override the restriction on attacking. They have no interaction with blocking because blocking was never restricted in the first place.
Concrete example: You control a Wall of Omens (which has defender). Your opponent attacks you. You may freely declare Wall of Omens as a blocker — defender does not prevent this. If Wall of Omens somehow also gained 'can attack as though it didn't have defender' this turn, it would now be able to attack and block, since both actions are available to it.
Bottom line: defender creatures have always been able to block. The ability's entire effect is the attack restriction, nothing more.
Unofficial fan resource — not affiliated with or endorsed by Wizards of the Coast. Answers are AI-generated estimates grounded in the Comprehensive Rules and are not a substitute for an official judge. Verify anything match-critical.