WASHINGTON—The Supreme Court on Friday agreed to decide whether the Trump administration acted lawfully when it canceled a program that provided legal protections and work permits to undocumented immigrants who were brought to the U.S. as children, adding a blockbuster case likely to be decided in the middle of next year’s presidential-election season.

The case, involving the Deferred Action for Childhood Arrivals program, or DACA, is a high-stakes affair for President Trump’s immigration agenda and for hundreds of thousands...