Under normal circumstances, when students leave school after graduation, the school will sometimes withdraw the punishment they received during their stay in school for the sake of their future (of course, it depends on the specific situation of your school, and not all schools can do this).
If you are still a student, ask the teacher in charge of archives in the Political and Educational Affairs Office if his punishment has been recorded in the archives; If you have graduated, ask if there are any disciplinary materials in the archives of the personnel department of the unit.
God can forgive the mistakes of young people. If you have been punished and have not graduated yet, I suggest you not wait passively. You can talk to the class teacher and the department counselor, listen to their suggestions, behave well in some aspects, and try to cancel the punishment before graduation. I think this may be the best solution.
I read your supplementary question again. According to the formal practice, the punishment must be notified to the person, sometimes publicized on the school bulletin board, and usually the time limit for the parties to appeal is given. It is impossible for a regular school to punish students secretly without saying it in the file. If you really do that, you can go through judicial procedures.