The cover of the detergent cup is not opening when its supposed to. If you need to expose the cup to investigate, it is not opening at all. The spring loaded cover is held closed over the detergent by a little catch. There is a solenoid in the door that pulls on the catch, letting the cover spring open. This happens at the start of the main wash cycle. The cover is not that water tight, water normally leaks in, causing the detergent to start caking.
Once the cover opens, exposing the detergent to the main water jets, the minor caking is not an issue, all the detergent gets washed out. When the cover doesn't open, the main water jets cannot wash out the damp detergent.
The reason the cover does not open usually is the solenoid fails and needs replacement, though it's possible something else is at fault. Faulty wiring, faulty relay or triac on the control board, some sort of timer issue, etc.
If you can locate the solenoid, try measuring the resistance of the coil with the wiring removed. If it's either hardly any or nearly infinite, the coil is at fault. Solenoids can fail for other reasons, so reasonable resistance does not mean it is not at fault.
Unless you can observe something out of place, like a broken wire, that is probably the extent of DIY troubleshooting.