Constructing bespoke algorithms is a skill which can be developed by attempting to solve difficult problems, and seeing how other people go about it, just like you are doing. There's no one-size-fits-all solution, but the more you do it the more tools and techniques you acquire to tackle problems. This problem can be solved very efficiently, even when the upper bound for the prime sum becomes much larger than a million.
As you already have seen, the use of prefix sums is a powerful way to cut down the work when you want to sum over a contiguous sub-array many times. Then the sum reduces in complexity to a difference between two prefix sums.
So first build an array of primes and their prefix sums. You can get a good upper bound on how many primes are in an optimal solution by finding the maximum number of primes that sum to less than the given upper bound. In this case with 1,000,000 there can not be more than 546 primes. Starting with l = 546, see if there is a sum of 546 primes which is prime and still less than 1,000,000. As the primes are an increasing sequence, the sum of the same number of primes but starting from a higher index, must be bigger, so you can stop once the sum goes over 1,000,000. If you still haven't found a result, reduce l by one and repeat until you do. Tackling the problem this way means the first solution you find will be an optimal example meaning while there may be other examples with the same number of primes, there are none with more primes.
I coded this in a C program and the runtime was dominated at all levels by the time taken to build the array of primes, the longest being 12s, then for 10^13 and below all <1s. Most consecutive primes which sum to a prime ...
(999998764608469) below 1000000000000000 is 10695879, from primes 7 to 192682309 inclusive.
(99999863884699) below 100000000000000 is 3503790, from primes 2 to 58954381 inclusive.
(9999946325147) below 10000000000000 is 1150971, from primes 5 to 17993449 inclusive.
(999973156643) below 1000000000000 is 379317, from primes 5 to 5476973 inclusive.
(99987684473) below 100000000000 is 125479, from primes 19 to 1662257 inclusive.
(9999419621) below 10000000000 is 41708, from primes 2 to 502237 inclusive.
(999715711) below 1000000000 is 13935, from primes 11 to 151051 inclusive.
(99819619) below 100000000 is 4685, from primes 7 to 45161 inclusive.
(9951191) below 10000000 is 1587, from primes 5 to 13399 inclusive.
(997651) below 1000000 is 543, from primes 7 to 3931 inclusive.
(92951) below 100000 is 183, from primes 3 to 1097 inclusive.
(9521) below 10000 is 65, from primes 3 to 317 inclusive.
(953) below 1000 is 21, from primes 7 to 89 inclusive.