A company may decide to fund open source software projects if those projects can create a significant revenue source for related products, not directly connected with source code or software.
An example of this case is O'Reilly & Associates, a publisher specialized in technical books. They paid some of the most important Perl programmers as a way to ensure continued development of the language, this way allowing for more sales of Perl-related books (which they publish).
Another example is VA Research, a seller of hardware systems preinstalled with GNU/Linux. They enrolled as developers many important Linux kernel programmers, thus helping to guarantee the continuous development of the Linux kernel. With a better Linux kernel, the areas of possible use of GNU/Linux expand, and with this the sales of Linux hardware. Even when other hardware vendors profit from this growth, VA Linux Systems owns a healthy market share of it, which justifies the spending of money for the general improvement of Linux. For instance, VA Linux is spending about 1 million USD in kernel improvement, while the overall market growth is of about 200 million USD, of which VA Linux systems has about 20% (or 40 millions), which leads to additional revenues of about 4 million USD. This obviously justifies the spending of the 1 million.
Yet another case is the writing of software needed to run hardware, for instance, operating system drivers for specific hardware. In fact, many hardware manufacturers are already distributing gratis software drivers. Some of them are already distributing some of their drivers (specially those for the Linux kernel) as open source software.
On other side, Red Hat is also a good example. They founded the Red Hat Advanced Development Labs, and hired several skilled programmers to work on strategic (for Red Hat) open source software (mainly the GNOME system). By funding this project they helped to create a valuable product for their main product (the Red Hat Linux distribution), while collaborating to develop new open source software.