The judge's decision came a day after the government declared a police state as it struggles to calm the violence in impoverished Andean regions that were the base of support for Castillo.
Peruvian President Pedro Castillo dissolved the nation's Congress and called for new legislative elections, but the Congress rejected the decree and voted to replace him with the vice president.
Pedro Castillo avoided joining the South American nation's list of impeached leaders as opposition lawmakers failed to get enough votes to remove him from office only eight months into his term