Hello @Teemu Salo,
Thank you for reaching out to the Q&A forum!
After reviewing the details you provided, I tested this scenario in my own environment. I created both a public and a private team to verify, and as you mentioned, the invited user encountered the same error.

I also tried resetting and sending a new code, but the issue persisted (both desktop and Web).
Currently, when I check the Service Health dashboard, there is no incident reported for this functionality.
However, I strongly recommend that you report this issue directly through the Teams app so that the development team can be aware of it.

Additionally, if this account is provided by your school, I recommend you contact your IT administrator to ask them to raise a support ticket to higher-level technical support so that they can investigate further.
To create a Support ticket, they can go to: Microsoft 365 admin center


When the ticket is opened, a support engineer can start a remote session to investigate the issue, review the back-end settings, and optionally run a sync tool to resolve the issue.
Find Your Microsoft 365 Admin: If you’re unsure who the Global Admin is within your organization, you can find guidance on locating them here: How do I find my Microsoft 365 admin? - Microsoft Support

I understand that in an education environment, joining by code is very convenient and this impacts your workflow. Since the same issue occurs in my environment as well, I believe that if more users report it, the engineering team will be able to prioritize and fix it sooner.
Once again, thank you again for raising this issue; it’s helped broaden my understanding. I hope you understand that I want to help as much as I can within the scope of this forum.
Looking forward to hearing from you!
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.