Can a company registered in Germany hire a remote worker based in Iran? What regulation act is applied in this case?
If by "hire a worker" you mean hire you as their employee, then no. And that has nothing to do with Iran or sanctions.
See https://expatriates.stackexchange.com/questions/23844/can-i-work-remotely-for-a-german-company-from-india-being-an-indian-citizen and just replace "India" with "Iran", or really "any non-EU country".
The only way you can legally sell your work and get money from a German company in Germany when you don't reside in Germany with a German work permit is being an independent contractor or company and invoicing the German company for services provided.
Whether this contract would be targetted by sanctions is a matter of that specific contract. It might depend on what work you do, and what you need to be given access to, while you work.
That said, what a company legally "can do" might still not be what they do. Hiring a lawyer to navigate this (because people on the internet are not the best source of legal advice) might well exceed any benefits they have from hiring you. Even if it is legal in the end, it might still be too costly.
Your best bet here is a company that already has dealing with contractors from Iran, already has lawyers for this on payroll and knows how to navigate this legally, not only in theory, but with their specific business dealings and services.
In case you are actually asking on behalf of the Germany company, you should already know all this. You should also know that the real answer is "get a lawyer". But just in case you are just curious and want a sneak peek, you can go to the website of the "Bundesamt für Wirtschaft und Ausfuhrkontrolle" and see what they say and how your specific company and the specific contract you have in mind plays with the regulations. Warning: there is no easy answer I could summarize here, it is multiple pages of references to applicable laws and regulations.
If your company has dealing with other nations, especially the US, you may want to check their conditions as well. Even though it might be legal in Germany, that does not really give you any protection from other countries sanctioning you in their juristiction or simply not giving you any further contracts because you don't play by their rules.
In addition to nvoigt's answer, it's worth mentioning that there are many things which may not be allowed to be performed by people in Iran by regulation or due to existing contracts with customers or suppliers.
For some, it's the simple fact that a person is not in the EU which may be an issue, for instance if there is any access to personal data protected by GDPR, any transfer of the data to or access to the data from outside the EU can be problematic.
For others, it may be related to export regulations preventing sensitive material (lots of electronics, computer hardware and software) to countries subject to sanctions.
Even if the company itself is not affected directly, some customers (especially the larger ones) may require the company to ensure and certify that everything is done in the EU, with no employees or subcontractors outside the EU, much less in sanctioned countries.
This closes the door to a lot of possible activities.