The Hungarian work permit is a residence permit that lets third-country nationals live and work in Hungary based on the employment of the applicant. For the application, you already need a labor contract (or at least a preliminary agreement) between the employer and the (future) employee, and when the employment is terminated, this must be reported to the immigration office within 5 days after the termination date, upon which the work permit will be revoked.
This does not mean that the third-country national will be deported the following day. There is an unofficial grace period of about a month, during which they can try and find a new employer. In that case, they will have to apply for a new work-permit with the new employer – while they can continue to stay in Hungary. If they have family members whose residency was based on their work permit, the same unofficial grace period applies to their residency, but if the main applicant finds new employment, the family members do not have to apply for a new permit, and can continue to use the existing one.