Yes, they can do this. If you don't have the $4k to pay back right now, talk to them and get on a payment plan or see what else can be done re: you paying this back.
It is possible for the people or software systems in financial aid to make mistakes, or to interpret rules incorrectly based on, for example, incomplete information or etc. If they did make a mistake, then they must require you to pay the funds back. The school has to ask for the money back, because the federal government has extremely strict rules regarding financial aid, what you can get when, how much you're eligible for, etc. Even if the school made the mistake, and as humans might want to let you keep the money, they absolutely cannot do so. They are required to fix the error now that it's been caught.
It's possible for mistakes like this to happen because the financial aid rules are thousands of pages long, often changing, and unbelievably strict. Again, it's the federal government (and in some cases, the states) that set most of these rules, and they are convoluted. One of the confusing, and frequently messed up rule sets is around taking classes in the summer term, and how that should have affected different types of aid you got in the fall and spring terms, and then again in the summer.
It sounds like the school/their systems didn't catch the situation at first, and gave you the aid. Then, in what was likely an audit, the error was caught. The school is required to get that money back from you and return it to its sources. They cannot let you keep it.
And there's no real way you would have recognized this error, no matter what the other posters say. The rules are convoluted, even the financial aid office at her school didn't catch this at first, different types of aid would be affected differently... If you sit down with the people in financial aid (for example, make an appointment with the Director of Financial Aid), they should be able to explain what happened and why. That doesn't mean you won't owe this money, but at least you'll understand what happened.