Altar of Dementia is an activated ability with the cost of sacrificing a creature. Activated abilities can be activated any time you have priority unless a specific timing restriction applies. During combat, players receive priority after each combat step (beginning of combat, declare attackers, declare blockers, combat damage, end of combat), meaning you can activate Altar of Dementia during any of these steps.
After the combat damage step resolves, both players receive priority again before the end of combat step. At this point, you may activate Altar of Dementia by sacrificing a creature, even one that just dealt or received damage. This is perfectly legal because sacrificing is a cost paid immediately when activating the ability — the creature does not need to be alive at end of turn or any other future point (CR 602.2a, 602.2b).
Note that sacrificing a creature to Altar of Dementia removes it from combat entirely. If you sacrifice an attacking or blocking creature after damage has already been dealt, the damage is already done — removing the creature afterward does not undo that damage (CR 509.2).
Example: You attack with a 3/3 creature. Your opponent blocks with a 3/3. After combat damage resolves, both creatures have 3 damage marked on them but are still on the battlefield momentarily. Before end of combat, you activate Altar of Dementia, sacrificing your 3/3 to mill your opponent for 3 cards. Your creature never goes to the graveyard from lethal damage — it was sacrificed instead, though the result for state-based actions is the same for the opponent's creature.
There is no rule preventing you from sacrificing a damaged or 'dying' creature to an activated ability before state-based actions are checked again, as state-based actions are only checked when a player would receive priority (CR 704.3). So the sacrifice resolves normally.
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.