Anything related to legality for something like this, depends on where you live.
Self-harm or attempted suicide can be illegal in some countries such as Japan. It is a criminal offense in others: see here for a list. You might not consider purposefully contracting coronavirus to be attempted suicide, and maybe 90% of the population will agree with you, but that does not matter if the judge involved in the case does not agree with you. This will depend very much on where you are living (do you live in a place where culturally, doing anything silly is taken extremely seriously and with harsh punishments? do you live in a place where judges follow the law to the letter or is it normal for them to act based on feeling? what is the "case law" or past jurisprudence in your country, for similar cases in the past?). The answer to your question is "yes" or "no" depending on a lot of factors.
The likelihood of you dying if you are between 10-39, is actually higher than you might think:

This means 2/1000 or 1/500. That is a higher chance of death than many types of "real" suicide attempt. If I offered you $5000 to take a pill which had a 1/500 chance of causing you death, would you take it?
Appart from "self-harm" or "attempted suicide" you could also be endangering others (via recklessness, negligence, mischief, or a number of other possible things depending on where you live). If you live in a place where healthcare is funded by tax-payers, you may be abusing the healthcare system.
Finally: having coronavirus once does not mean that you will be immune to it. Already there has been a case in Japan where someone released as "recovered" was diagnosed with coronavirus a second time. See this article: "CAN YOU GET COVID-19 TWICE OR DOES IT CAUSE IMMUNITY?" which says that the anti-bodies (that means "immunity") you develop from having coronavirus once, seem not to last very long at all.
And this article says that people that recover from coronavirus might have 20-30% of the lung function they had before.
Please do not purposefully infect yourself with coronavirus.