Yes. This is not only safe but best practice. Tuck the capped wires completely into the junction boxes to avoid accidentally snagging on passing ladders, wallboard, etc. If the room continues in general use then install blank cover plates.
Can an exposed live wire cause a fire?
As many of us know, exposed wire creates a fire hazard. An aging system with worn-out insulation that leaves wires exposed is vulnerable to power surges, overheating, shorting out and encountering other elements in the wall that can cause a fire.
Do you need to cap ground wire?
Tip. Bare copper ground wires do not need to be capped. Similarly, BX cable’s metal armor sheathing, which conducts to ground without the need for an additional ground wire, may be left alone.