As such, there are no statutory or legislative provisions that prohibit a person from working in any organisation.
The only restrictions that apply in the situation that you describe above emanate from employment, contractual, partnership and other similar agreements or contracts.
Collectively and popularly, these restrictions are referred to as 'non-compete provisions'.
If, at time of accepting employment with company X your 'contract of employment' or 'letter of appointment' contained non-compete clause/s, and you signed that letter or contract having been made fully aware of such clause/s by company X, then company X may be within its rights to object to your working for company Z.
But, its not as cut and dry as I've made it out in the previous paragraph. That is intended to give you fundamental info re: a non-compete clause.
Its one thing to have an non-compete clause. Its another thing to determine its veracity, its legality, its fairness, and above all, its enforceability.
The Supreme Court of India has (in the recent past) declared unanimously that any non-compete clause that infringes unfairly and unjustly upon an individual's or a company's constitutional right to participate in employment or conduct business as their source of primary income in an area where that individual or company have core skills and those activities form their core employment or business activity, then any such clause is unjust and unenforceable.
And, even where the Supreme Court has found non-compete clauses to be legally sound, it has frowned upon any period of non-compete exclusion that exceeds 3 - 6 months (for companies) and 2 - 4 weeks for individuals.
And, the Supreme Court has also held that where a non-compete clause exists and the plaintiff intends to execute such clause, then in such circumstances the plaintiff MUST compensate the disadvantaged party/s to an amount not less than the last highest compensation which the defendant was entitled to immediately prior to the separation of both parties.
This is a very common occurence for merchant bankers, brokerage firms, legal firms etc... where the disadvantaged party is prohibited from conducting any employment or business activity for up to 6 - 8 weeks post-separation. But, then the disadvantaged party is compensated in full for the entire duration of non-compete provisions.
These judgments have had a significant impact on partnership agreements and appointments of senior executives.
In your case though, it could well be a case of bruised prestige or sour grapes. Because, the truth is that if you were a contractor with company Y and they sub-contracted you to work for company Z, there is literally no remedy available to X to pursue a non-compete clause even if its crossed all the t's and dotted all the i's.
Also, the fact that you've been gone from X for over 2 months, you stand on good grounds, even if X were to litigate against you. And, to litigate, they must first send you formal 'cease and desist' notification citing enforceable provisions from your contract or appointment letter when you first started to work for them.
DISCLAIMER: My reply to you on this post is intended as information ONLY. I am NOT a lawyer and do not intend for this post to offer you, or for its contents to be substituted for, construed (or misconstrued) whether inadvertently or by design, as legal advice - implied or explicit. I strongly encourage you to seek legal advice from a qualified and authorised lawyer to ensure the veracity of information upon which to arrive at an informed decision re: next steps.
I hope this helps you. All the best!