The CPF (Individual Taxpayer Registry) is the record the Federal Revenue Service uses to identify any individual before the Brazilian State, whether resident in Brazil or not. For a foreigner, it ceases to be optional the moment their asset, financial or corporate life gains any point of contact with the country.
This happens, for example, when the foreigner buys a property in Brazil, opens an account at a Brazilian bank, makes a financial investment, comes to hold a stake in a Brazilian company, acquires other registrable assets, applies for certain visas or simply needs to present themselves before a Brazilian public body. In all these situations, the CPF is what makes it possible to identify that person unambiguously before the Federal Revenue Service and the other bodies and institutions that rely on it.