I think I found a suitable solution. Thank you for the help @Jinwei Li-MSFT and @sadomovalex . The PnP Module's error message was a key thing to get me to the solution.
The solution is that I created a channel in the team that has the same name as the folder. Then I deleted the channel. After that delete option appeared on Sharepoint and I was able to delete the folder.
This is the source I used https://techcommunity.microsoft.com/t5/sharepoint/channel-folder-cannot-be-deleted/m-p/3545032/highlight/true#M61145 so thanks goes to Ruben_Jobse. It was great to find solution for this after a while of searching.
Regards,
Pekka