Generally speaking, the rules for when a provider is or is not allowed to collect a copay are driven by the provider's contract with the insurance payer, and with that payer's policies, which a provider agrees to abide by when they sign the contract. To get a definitive answer, your best bet would be to discuss this with the particular payer.
Some providers do collect a copay or an estimated amount due at every visit just as an office policy, and there is nothing wrong with doing this. But the payments collected must be applied to some charge, and if there is no change posted, or if the bill is paid in full, then the credit is returned to the patient or applied to the next visit.
But to retain a copay when no charge has been made, or when the claim is processed by insurance and the determination is made that no copay is due, then the provider cannot just keep the money - that would be fraudulent accounting, like pocketing money from the cash register, so to speak. If the patient has concerns, they always have a right to request an itemization of their account, which would show the payments that have been made and the charges to which they have been applied, and these should either balance to zero, or show an amount due or a credit. This is just standard accounting practices.