It is not necessary to detrend the series although the trend has to be dealt with and detrending is one of the options but there are also other options.
Other options include explicitly modeling the trend. For example, many tests for cointegration including Johansen cointegration test, it is possible to estimate the test together with a linear or quadratic or other deterministic trend terms. The only issue there is that with some cointegration tests the test statistics with and without trend and critical values are different, but most modern packages/programs already provide adjustments for some common deterministic trends - for example linear or quadratic trends. Hence in such cases this might be preferable to detrending.
However, detrending the series is still an option. The problem with detrending is that you are modifying the series itself and there is always a risk that when you remove trend you are also throwing away some other information that the series had. Nonetheless, it is still a valid option.