While the situation is complicated somewhat by the fact that you were the one who purchased the lock, I still believe the answer is: yes, he does have that right.
The landlord is the owner of the property; you are merely renting a room. While you are entitled to use and occupy the space privately as you see fit pursuant to the terms of the lease, you cannot leverage this position and lock the landlord out of space which he both owns and is to a large extent responsible for. The landlord cannot freely enter your room whenever he chooses, and must give you reasonable notice (24 hours) to do so, but he does have the right to enter to show other prospective tenants, to perform repairs, and for other purposes.
If you don't comply, the landlord could hypothetically (a) let you get away with it (seems unlikely), (b) change the locks and possibly charge it against your security deposit, or (c) evict you.
Douglas Lloyd is licensed to practice law in the Commonwealth of Massachusetts. Answers provided on Avvo are intended for informational purposes only; they are not intended as legal advice and do not create an attorney-client relationship. The material is presented with the understanding and agreement that I am not engaged in rendering legal or other professional services by posting it.
I cannot determine from your question whether you have exclusive use of a room or whether you are one of 7 people renting half of a two-family home. Roomers do not enjoy all the rights of tenants. In general, a landlord should apply to court and not just come in and change anyone's locks, except in an actual emergency; but without a lease, the landlord clearly has the right to evict you on short notice if this disagreement about the key cannot be resolved, so you need to consider how important the principle is to you.
Disclaimer: This site exists to provide information only. It is not legal advice. Answering your question does not create an attorney-client relationship. I am a Massachusetts lawyer. Any information provided on this site does not, except as explicitly stated, imply familiarity with laws or procedures peculiar to your state which may differ from those where I practice.