It might be constitutional, but "confidential" just means the state can punish any state employees who give the images to the general public.
Marking something "confidential" has no effect on the general public who receive the images, including any newspapers that ultimately publish them.
McCarthy knew that a government shutdown would have pissed off even more Republicans in Congress, including all of those in vulnerable districts.
For example, Boebert's district. Notice how for once she didn't vote alongside Gaetz? Behind closed doors, there were plenty of Congressional Republicans telling McCarthy that making make a deal with Democrats was preferable to a politically suicidal shutdown.