@Nikolaj LARSEN Thanks for reaching out. I had tried this at my end and below are my observations.
We have this option "Subscription required" for an API in the settings tab.
If you don't pass the subscription key in the request, and your API is configured to require a subscription key, Azure API Management will return a 401 Unauthorized response with an error message indicating that a subscription key is required before even the policies are executed.
If the "Subscription required" option is unchecked, Azure API Management will not look for the subscription key in the request for authentication. In this case, the context.Subscription.Id expression will evaluate to null. Thats the reason you get 500 response code.
Please verify and do let me know if you have any queries.
Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.