How long is a herpes lesion on the hard palate of the mouth contagious?

2wk. As long as the lesion is present it may be actively sheding virus. It is usually self limiting but trauma can keep it going. Once the lesion has completely healed an no other lesions evident the host is relatively low risk for passing along the virus.
Short & long answers. The short but not-quite-correct answer: you're contagious only when a sore is present. The longer, more correct answer: you can shed virus from the mouth even if you do not have an active ulcer; but you are most infectious when an ulcer is present. However, you cannot give it to someone who already has it - and 60% of the population already has it. So try not to worry about it too much.