What is ethical?
Since you're specifically asking whether or not it's ethical, it may help to frame the problem in terms of different ethical systems. This is a contentious subject and I am by no means an expert, just an opinionated man trying to help, (and one who happened to really enjoy his ethics class in college,) so keep that in mind.
Also note that these different systems rarely agree on what you should do, it's up to you to decide which is most relevant. There are many, many that I'm not including here.
Postmodern ethics hold that human affairs are a messy thing for which no single system provides a comprehensive answer. So we may work from a system as a base to address the majority of issues, and then incorporate others to deal with outlying issues.
Business ethics
It sounds to me like you are most concerned that your own code of ethics may conflict with the business ethics of your company. Different folks have different ideas on what the ethics of a business should be, but we don't need to go off on a tangent about that. Your company should have a written Code of Ethics, or Code of Conduct, or some-such. You can find it, read it, and see how your own ethical code resolves against it.
But those documents are typically more high-level, upper-management directives which derive from their rights and responsibilities as a business and employer within the nation(s) they inhabit. Ideally it provides a Rule of Law on which to build policy, but it may also include day-to-day behavioral directives for employees. Take a look.
Confucian Ethics
Kong Fuzi's ideas seek to strengthen society by reinforcing harmonious interpersonal roles. It has done so successfully for many centuries by leveraging the power of human emotion and irrationality to positive effect. You yourself have said there will be no such interpersonal role of mentor-student. Therefore, Confucianism suggests that you must strengthen the harmony of your organization by building upon interpersonal roles you do have, such as coworker-coworker, employer-employee, supervisor-supervisee.
How this is done, only you can know. Maybe it just means doing what you can to make the workplace a better place for everybody before you're gone. Perhaps it means talking to your supervisor about how their expectations and your expectations played out during your tenure, and what that means for the next guy. Perhaps something else.
The key point here, though, is setting aside your own ego. Currently you are thinking of the problems you've encountered and how to mitigate them for your successor. Within the Confucian school of thought, however, this would be considered selfish. (Yes, even though you're concerned for another person.)
Utilitarian Ethics
This system is in the tradition of John Stuart Mill. It holds that the right action is the one that results in the most "utility" -- a measure of happiness that is not necessarily objective or empirical. The goal is to attain the most happiness for the most people.
(Off-topic: Saturday Morning Breakfast Cereal has an amusing comic about this one.)
Its application here isn't so bad. Utilitarianism suggests that you focus on providing comments and documentation that will most efficiently get your successor up to speed. They don't need full mastery, they just need a level of productivity that satisfies themselves and their supervisor. And your own utility is factored into the count -- if it starts making you miserable, move on to other things.
Kantian Ethics
Immanuel Kant. Big name in ethics, and his stuff quickly delves into the abstract. The quick-and-dirty summary of his ideas is that something is truly right and good only when it is not qualified. Thus the end does not justify the means, nor do the means justify the end -- each must stand on its own. In that sense, the only ethically relevant consideration when deciding on one's motives for doing so. The motive that Kant proposed was duty and obligation.
There a lot to criticize in this system, but it's worth thinking about as one of many options. You have a duty and obligation towards your employer, but not to your successor. Some of that duty may entail preparing source code and documentation for your successor to carry on your duties. Whether those materials are what you want, or what your successor wants, is irrelevant. Even should the materials prove inadequate, you have fulfilled your duty, and at worst your successor simply has somewhat more onerous duties to fulfill.
Pragmatic Ethics
In the tradition of John Dewey. This system holds that ethics themselves are a scientific process of experimentation, iteration, and revision. Furthermore, it holds that ethical behavior is conducted not by individuals but by societies. It also proposes that ethics are context-sensitive, changing with time and place.
The downside of this is that it's descriptive of how ethical decisions are made, and not very prescriptive of how to make ethical decisions. But it does suggest decisions on what is right and wrong (such as your comment, ...against my better judgment...
) are no longer yours to make. The right-and-wrong of these decisions belong to society, on whose behalf your company makes the decision, on whose behalf you yourself make the decision.
Once you are gone, you are no longer in a position to make these decisions on behalf of the company. Therefore, such decisions are only relevant insofar as they allow your successor to do the same. If they think your opinion is hogwash, then opinion comments have no ethical value.
Therefore, in this system, the ethical action is to enable informed decision-making by your successor, with an emphasis on empirical information, so that they be better prepared to conduct the next iteration of decisions on what is right and wrong.
Ethics of Care
This is the tradition of thought that follows from Carol Gilligan's work on psychological development in women. Setting aside feminist issues, it holds that what is good and right depends on how one cares for others; nurtures development; and promotes well-being.
From that stance, professionalism doesn't even matter in this scenario. You have someone who is going to inherit your position, and you're not going to be there to help them. Ethical care suggests that you should do whatever you can, now, to give them the mastery you now hold over the source code. That includes objective knowledge that can be used in analysis, as well as subjective knowledge that can be used in judgment.
Conclusion
Answer unclear. Read, think, mix-and-match, adjudicate.