For the pages that are not mobile optimised (the operations that are done on the page should be only from a desktop. Imagine some kind of a development tool which would be used only from a desktop and almost impossible to use on a mobile), I redirect users to a standard page that says "Please use the feature on a desktop for best experience". Should this page contain a "Continue Anyway" link at the bottom? Essentially, should I give the user an option to go the page on a mobile and have a bad experience anyway? Or should I just not allow him to use? What are the cases when it is okay to give the user an option?
Always let the users express their intentions. In any case, as an UX designer, it's your work to define the possible avenues the user may take. In this case, you can allow this avenue or block it.
If you block this path, then the continue anyways message shouldn't exist at all. Instead, simply explain in a very clear way why they can't do this action and the steps to successfully perform it (e.g.: use a desktop device).
If you allow continuation, then you MUST explain what will happen and then let the user choose whether to continue or not. And if they choose to continue, they will see your tool isn't meant to be used on small screens and understand they need a laptop. DO NOT be scared of losing the user, any user interested in your tool will use the appropriate device. And if they don't, they weren't interested anyways.
As an additional solution, you can offer to sync their mobile with their desktop version, which in fact won't do much that remind them to use it on desktop (with a mail alert or whatever) .
What is the basis for your restriction? Just think ahead a few months, and the resolution on a good mobile will match the resolution of a bad desktop. Or do you need to have the user seated because your site has really bad news - just kidding.
If you say, "Ooops, we didn't expect you to use this feature on a mobile, please excuse bad layout", that'll prepare people for any glitches. I also would hate to be stopped if I needed this function now.
EDIT: Responding to your comment: People are extremely creative in working around obstacles when they really need to. And I just cannot imagine some kind of function which might be so hard to use on a mobile to be made unavailable.
I highly recommend not blocking the user from using the site because it's not "optimized". Users will abandon the site in large amounts if you gate them in such a way. It's better to allow them to go to the page and include an information banner or some other noninvasive component than to gate them. That way the user can decide if the page is worthy of their time and frustration.