Are there restrictions on how recipient countries can use foreign aid money coming from the U.S.? Or can recipient countries can use it any way it want to use it? I heard that recipient countries can only use it to buy goods and services from the U.S., but I somehow doubt that it's true, because recipient countries would probably use a large part of the aid money to hire government workers and local contractors.
Donors can attach conditions when they give aid. What those conditions are differs from aid program to aid program.
- Respecting those conditions is not part of international law, it is part of bilateral agreements between the donor and the recipient.
- Aid may be structured so that no money flows to the recipient. Instead they get goods and services, paid for by the donor government, delivered by companies in the donor country.
Imagine the US government decides to send a ton of rice to a starving country. That rice is grown in the US, packaged in bags labeled "aid from the US," and flown to the destination in USAF transport planes.
But there are other cases as well. Imagine the US government decides to help a foreign country fight terrorist. They send troops to train the local army, weapons and equipment, and possibly cash as well to pay the recruits.
You don't give money to the government
The general practice in humanitarian aid programs is that you establish local organization(s) that implement the goals, and they are not controlled by the local government but by managers appointed by the donors. These organizations receive money, hire people (which may be from the donor country or locals, depending on their goals) and distribute the aid, sometimes directly and sometimes using local NGOs. Such an organization may also have a mandate that restricts the use of its money to e.g. buy only goods and services from a particular country.
The PR titles may say "we decided to give $X million to Elbonia" but that's a simplification which often means something like assigning $X million to the Foundation for Elbonian Support which will be established shortly; not to Elbonian government.
There are cases where, for example, aid for recovery of a major natural disaster or war gets given directly to the local ministry of healthcare, or military aid gets given directly to the local defense ministry; but for foreign aid that's aimed to help the local population in third world countries often the government is intentionally side-stepped precisely for the reasons you mention.