There are two types of Rules.
- server-side
- client-only
If the rule set is on the server side then even if you are not logged into your email account, the rules will be applied to the email immediately.
But if the rule is set on the client side on a Mac then the rule will be activated only when the Mail app is open and is online on the Mac.
This is truly based on the conditions and actions you apply to them.
- iCloud / Gmail only has a Client-side rule option
- Outlook / Exchange has both options, Server and Client side rules can be set
You cannot set a rule on an iPhone. It will follow the rules set on server or at the client end.