If after that, if it's general mental or physical fatigue, it might be medical. Are you able to passively take in information, like watching TV attentively without getting distracted/tired? If not, then yeah, suspect medical or psychological issues. Everyone gets that way sometimes, but if it persists more than a few weeks, talk to an MD.
If you're having trouble beginning code tasks, then work on stuff that you're already in the middle of, write documentation, go through the bug list of whatever you're supposed to be working on and fix issues, etc. This can get you back into it.
I think really great programmers are in an inspired, highly productive mode almost all the time. Ordinary pretty good programmers (most of us here) are in that mode some of the time, and need to develop the skills and habits to keep plugging along when we're less inspired. That is partly a matter of technical fluency: be very familiar with your tools, languages, environment, code base, etc., so you can keep cranking without having to get too overwhelmed by uncertainty and confusion.
There is a long time stereotype of hackers staying up all night coding, and that is partly because there's a time around 4am when psychological resistance to doing stuff dissolves. So if you are stuck on something, deciding to pull an all nighter can actually help break through, even if most of the night is not productive. Don't do that too often though, and never do it 2 days in a row.
Other than that, I guess we would have to know more specifics.
This sounds like exhaustion, possibly burnout.
It could also be something more serious. You should consult physical & mental health professionals.
Look up the Maslach Burnout Inventory and request that specifically to rule out burnout:
https://en.wikipedia.org/wiki/Maslach_Burnout_Inventory
In general, don't seek or follow medical advice online. Including on HN, or from me.