There's a pretty good exploration of these periods of boom and bust in software development productivity from Joel Spolsky: https://www.joelonsoftware.com/2002/01/06/fire-and-motion/
I read it years ago and it really helped me disconnect the feeling of personal failing from those days/weeks of being a professional software developer where things just don't click.