It’s tough to go back to school in your 40s. But with layoffs, stagnant pay and inroads by artificial intelligence, many of those nearing midlife are heading back to classrooms and trade schools.