Because they are two different types of payment. Debit comes directly out of the account, similar to cash or a check; credit is is - credit, paid off 1x per month. Also retailers and gas stations have different fees for each type of transaction.
Most businesses have a policy against taking debit cards as they are not as reliable as credit cards. This is partly the reason why cashiers ask you. When using a credit card, it is much harder to get conned, but it is much easier using a debit card.