I've always wondered this. Occasionally I declare medicines, or wood carvings or whatever when going through customs. The point of asking you to declare these things is so that they can inspect and prevent say, bug-infested wood from entering New Zealand.
There's usually an amnesty box as well - if you realise at the last minute you have fruit, which you can't bring into New Zealand (just using NZ as an example here), you can dispose of it in their bins, no problem.
Not that I ever would - but hypothetically, if someone came through and for some reason realised they had their illegal drugs stash on them - class A - something really illegal, and they declared it - would customs simply say "thanks for declaring that, we'll have to take that off you as it's illegal in this country" or would they arrest you?
EDIT: For the sake of argument as some countries will probably differ, let's assume the US for the accepted answer.