I think I found it! Richard Hamming, mathematician and Turing Award recipient said it in a 1986 seminar at Bell Labs. The talk was titled "You and Your Research", and a transcript is available here. The most relevant part is in the Q&A session after the main talk:
Question: You mentioned the problem of the Nobel Prize and the subsequent notoriety of what was done to
some of the careers. Isn't that kind of a much more broad problem of fame? What can one do?
Hamming: Some things you could do are the following. Somewhere around every seven years make a significant, if not complete, shift in your field. Thus, I shifted from numerical analysis, to hardware, to software, and so on, periodically, because you tend to use up your ideas. When you go to a new field, you have to start over as a baby. You are no longer the big mukity muk and you can start back there and you can start planting those acorns which will become the giant oaks. Shannon, I believe, ruined himself. In fact when he left Bell Labs, I said, "That's the end of Shannon's scientific career." I received a lot of flak from my friends who said that Shannon was just as smart as ever. I said, "Yes, he'll be just as smart, but that's the end of his scientific career," and I truly believe it was.
You have to change. You get tired after a while; you use up your originality in one field. You need to get
something nearby. I'm not saying that you shift from music to theoretical physics to English literature; I mean within your field you should shift areas so that you don't go stale. You couldn't get away with forcing a change every seven years, but if you could, I would require a condition for doing research, being that you will change your field of research every seven years with a reasonable definition of what it means, or at the end of 10 years, management has the right to compel you to change. I would insist on a change because I'm serious. What happens to the old fellows is that they get a technique going; they keep on using it. They were marching in that direction which was right then, but the world changes. There's the new direction; but the old fellows are still marching in their former direction.
You need to get into a new field to get new viewpoints, and before you use up all the old ones. You can do
something about this, but it takes effort and energy. It takes courage to say, "Yes, I will give up my great reputation." For example, when error correcting codes were well launched, having these theories, I said,
"Hamming, you are going to quit reading papers in the field; you are going to ignore it completely; you are
going to try and do something else other than coast on that." I deliberately refused to go on in that field. I wouldn't even read papers to try to force myself to have a chance to do something else. I managed myself, which is what I'm preaching in this whole talk. Knowing many of my own faults, I manage myself. I have a lot of faults, so I've got a lot of problems, i.e. a lot of possibilities of management.
The Shannon referred to in the quote would be Claude E. Shannon, who is often called "the father of information theory". Shannon laid the foundations for this discipline while at Bell Labs, and in his talk Hamming suggests that Shannon would not continue to "plant acorns" afterwards.
While it isn't really phrased as a recommendation for others, it is perhaps also worth noting that
Donald Cram (1987 Nobel laureate in chemistry) has said
To retain my fascination with chemistry, I have had to change my research fields about every 10 years.
This quote can be found in I. Hargittai (2003) Candid Science III: More Conversations with Famous Chemists. Imperial College Press, p. 192.