Charities have to account for their incoming and outgoing resources as different types of funds.
Unrestricted funds are funds the charity receives to further its objects. These can be donations, grants or fees earned. If a charity has narrowly defined objects, then a grant it receives may be a perfect fit for its objects and so be unrestricted (even if the funder specifies that it expects the grant to be treated as restricted). The recipient charity has to judge whether new incoming funds are restricted or not.
Restricted funds have to be used for the purpose for which they were given. This purpose will be narrower than the charity’s objects. A donor can require the charity to spend their donation in accordance with their wishes. This creates the restriction, which is an obligation under trust law.
Grants are a form of donation and can be subject to the type of legal obligations that apply to restricted funds. So a funder can specify that they wish their grant to be used to help a specific group of beneficiaries, or support a particular project. In these situations, the grant would be treated as restricted income. The recipient charity is obliged to use the grant for the purposes for which it was given. If some of the grant is not used, then it has to be offered back to the donor as it was given for a specific purpose.
On the other hand, contracts are by their nature not donations and therefore cannot be treated as restricted funds. Contract income should be treated as unrestricted income. The recipient charity is obliged to meet the terms of the contract but is not required to spend all of the contract fees on the specified activity. Thus, a charity can make a surplus on a contract, which it may keep and add to its reserves.