Can your school push back your graduation and make you do summerschool if you failed a non-required course?

Just to set things straight, back in the first semester, I initially had 2 study halls(because I have all my credits ) but my school wouldn’t allow it, and gave me computer programming which isn’t required. Obviously I don’t know shit about coding and failed with a 54%. But given I didn’t need that course, and was given it against my own will, are they legally allowed to hold back your graduation?

I’m still going to check with my counselor to see if they made a mistake, because they sent an email to every student who failed a first semester course, and may have accidentally included students who are eligible to graduate.