President Trump said he wore masks “when needed” but mocked Joseph R. Biden Jr. for regularly wearing masks in public