Yes, it can be done.
How, minutes in both corporations recording the transfer and cancel your ownership of X and issue a new certificate to Y. Did you file an exemption from filing a permit with the Commissioner of Corporations when you first issued your shares?
The above is general legal and business analysis. It is not "legal advice" but analysis, and different lawyers may analyse this matter differently, especially if there are additional facts not reflected in the question. I am not your attorney until retained by a written retainer agreement signed by both of us. I am only licensed in California. See also avvo.com terms and conditions item 9, incorporated as if it was reprinted here.
Couple extra thoughts. The reason you want to do this is very important and you do not give us your goal and objective in this regard. There are also some other important matters you need to consider that have tax ramifications you may not be aware of. Are the 2 corporations c-corps or s-corps or one of each. An s-Corp can own shares in a c-corp but not so the other way...ergo potential problem if you are not aware of this. If the 2 entities are c-corps then you may not want to risk the value of one company by making it an asset of the other company in terms of a creditor claim. Perhaps it would be better to form a parent company and then contribute both companies to the capital of the parent to create a consolidated tax return suture assuming the two companies are c-corps......these are t a few of the facts I would want to give you an answer to whether it makes sense or not.
My answer is not intended to be giving legal advice and this topic can be a complex area where the advice of a licensed attorney in your State should be obtained.
You do need to address the s-corp and c-corp issues before making the transfer. You should also discuss your reasons and rationale for this planned step, and the corporation's status and issues regarding the original stock issuance, with an attorney to avoid problems downstream. I believe all of the answers provided assume that your corporations were formed in California, but you have not provided that information. These particular facts, and several more, are necessary for an answer upon which you can rely.
The foregoing is not offered as legal advice, but is a general analysis of the situation posed by your question. I am not your attorney until I have been retained through a written retainer agreement which is signed by both of us. I am only licensed in California and make no representation as to the laws of other states.