while the reason is … what it is, the answer is yes, you can do it if you like.
UAs will probably try and make the best of it and render correctly.
you need to go further with your thinking, this is just a bad idea while the other attributes will make sense to another person changing your code, it will certainly be harder to keep it consistent after a while, considering that every time you change the value for the attribute you need to remember to do so also about its twin.
you’ll end up with invalid markup and its purpose defeated:
<!-- Lots of code and newlines here -->
No, you shouldn’t do that. I can’t see what you’re hoping to gain from it.
The usual method of putting a <!-- end beer –> comment works perfectly well, and I see no need or benefit to changing it. Putting the id inside the closing tag would seem to imply that the browser should know which tag it is closing, which leads to obvious questions as to what it should do if you’ve opened <div id=“beer”> but you then close </div id=“cider”>.