If the data generating process was fixed over time, you would choose the longest available data sample for cointegration testing -- because a larger sample yields higher power for the test.
If the data generating process is changing over time, then you would identify the time period of interest and use only the corresponding subsample to test for cointegration -- because the test results would differ across periods/subsamples.
If the test results change depending on the period/subsample (your case), it is likely that the data generating process is changing over time (across subsamples). Then you have to choose the subsample of interest and test and make inference for that particular subsample, being aware that inference might not hold for other periods/subsamples.
Edit addressing the comment
I'm looking for cointegration because I want to be able to trade a pair of stocks that is both (1) cointegrated in my backtest and (2) will likely be cointegrated in the coming months.
This is a very challenging task, and you can never be guaranteed that the data generating process will remain the same over time, especially when it comes to financial time series. There is essentially no way to tell whether cointegration will or will not be present in the future. But you can try theoretical argumentation such as if shares of a company are traded on two exchanges, the prices in the two exchanges should not deviate far away from each other.