Can mathematics professors do consulting work external to their university?
Is it generally true that mathematics professors do not / cannot engage in consulting work external to their universities?


No, it's not true. Doing external consulting may be less common among mathematics professors than among faculty in certain other academic disciplines, but it's fairly common nonetheless. The professor would need to make sure that the consulting arrangement they are entering into is compatible with their other responsibilities, and specifically (in connection to the theory you mentioned in the question) the intellectual property policy of their university. While this issue is not something to be casually dismissed and certainly it can create difficulties in some cases, there are still many consulting opportunities in which the work the professor wants to do would not be in conflict with their institutions' IP policies. Examples may include:


The professor is on unpaid leave from their institution so the IP policy doesn't apply.
The professor is doing the consulting over the summer when they are not receiving a salary, so again the IP policy doesn't apply.
The consulting work is of a kind that generates deliverables such as code or data analysis that the IP policy doesn't apply to. Specifically, in the U.S. all university IP policies I'm familiar with apply only to patentable inventions and do not cover copyrightable content, which remains the property of the faculty member. If the consulting work does not require anything sufficiently creative that it might result in a patent, there is no conflict. (Of course, the professor still needs to make the contracting company aware of their IP-related commitments and let the company make the decision about whether they are willing to take the risk of losing rights to a valuable patent. It seems likely that some companies in some situations would be averse to entering such an arrangement, as you described in the question.)
The consulting work is in an area sufficiently unrelated to the professor's area of research that the IP policy doesn't cover the work.
The professor takes sufficient care to perform the consulting work on their personal time and without using any university resources. In that case, depending on the legal jurisdiction it may be the case that the IP policy cannot legally apply to them, since courts in certain places have ruled that an employer does not own work their employee has created in the employee's private time and using private resources, even when the employer claims otherwise.


Finally, I was discussing consulting to commercial enterprises, but mathematics professors also engage in various other forms of consulting to governmental and non-profit organizations, where IP restrictions would usually not be much of a consideration. For example, in the U.S. it is quite common for professors to be invited to sit on panels for the National Science Foundation and other funding agencies. This is a form of paid consulting, although it usually doesn't pay very much.