He got work from al-Baatin [a company] and the one who hired him cheated the company and got a lot of money as a result, then gave him some of it
Question

I have a company, and I managed to get some work for al-Baatin from another company [as a subcontractor]. This company got the contract from yet another company. The agreement was that after I finished my work, the company which gave me the contract would work out the quantities [of materials used] and send that information to the main company that had awarded the contract, and after they got paid, they would give me my share of that money. At the end of the contract, the company that gave me my contract did what I mentioned above, and gave me a sum of money more than I deserved, and many times more than I expected, because they cheated the main company which awarded the contract. Thus my share increased because their share increased, as a result of what the company did of exaggerating the quantities [of materials used], with no justification. What is the ruling on the money that I received, which is more than I deserve, noting that I cannot return the money to them, and I cannot tell the company that awarded the contract what happened?
Praise be to Allah.Firstly:
It is permissible for the one who is hired to do some work to hire someone else to do that work for a lower fee, so that he can benefit from the difference in wages, unless the agreement stipulated that the first worker should do the work himself, meaning that there was a reason for choosing him in particular to do the job, such as one who hires a well-known calligrapher or designer.
It says in Kashshaaf al-Qinaa‘ (3/566): If the hired worker accepts and commits himself to doing some particular work in return for a fee, such as tailoring and the like, then there is nothing wrong with him subcontracting someone else and paying him less than that fee, because if it is permissible for him to give the job to someone else to do it in return for the same or a greater fee, then it should be permissible to subcontract it for a lower fee, as when buying and selling, or renting out an item. End quote.
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said: If someone is hired to do some work and to be responsible for it, such as if it is said to him: We want you to clean this house every day, and you will have one hundred riyals per month, then he hires someone else to clean the house every day, as stipulated in the contract, but for fifty riyals, that is permissible, because this is akin to saying that it is permissible for him to sublet [a property] for the remainder of the rental period for more than he is paying in rent. This is how people do business nowadays. So you see the state, for example, making a deal with a company to clean the mosques, each mosque for such and such an amount of money each month, then this company brings in workers who do what is agreed upon in the contract, for less than a quarter of what the company agreed upon with the government.
That is unless the reason for hiring a particular person is different. So if the reason is different, it is not permissible [to subcontract the work]. For example, if you hired a person [a scribe] to copy Zaad al-Mustaqni‘ [a book of Hanbali fiqh] for you, and you know that this man has good handwriting and makes few mistakes, then he hired someone whose handwriting is also good for less than you hired him for. In this case, the scholars say that it is not permissible, because what matters is the accuracy of copying, not just good handwriting. Rather what matters here is handwriting and punctuation marks, and making no mistakes in writing. How many people there are who have the most beautiful handwriting, but when they write they make mistakes, such as replacing the Arabic letter daad (ض) with za’ (ظ). This is a mistake, and many of those who have beautiful handwriting do not follow any rules when writing, whilst many of those who have bad handwriting that no one can read except one who has got used to it write correctly with appropriate punctuation marks and the like.
Whatever the case, what matters is that if there is a purpose in choosing a particular person to do a job, it is not permissible for him to let anyone else do it instead of him." (Ash-Sharh al-Mumti‘  10/39).
Secondly:
If the one who gave you this job cheated and took more than he deserved, and gave you some of that money, it is not permissible for you to keep anything except what you agreed upon. If you did not agree upon anything in the contract, then you are entitled to the going rate.
You must return the extra money to the company which awarded the contract, and put it into the company’s account by any possible means, or you can do some work for them for free that is equal to the extra money that you received.
If you cannot do that even after trying hard and looking for means of doing so, then you must get rid of it by giving it in charity with the intention that the reward should go to the rightful owners of the money.
And Allah knows best.