The legality of keeping squirrels in captivity varies by location.
Generally, it is not illegal in the United States, but state and local laws may require licenses, restrict species, or ban ownership. Certain endangered species are illegal to own. Proper housing, diet, and enrichment are crucial.
Research your local laws before acquiring a squirrel. Resources include your state's Department of Wildlife Resources and local animal shelters.