The cuánto refers to cuesta, not to mantequilla. If you were asking: How much butter do you have? then it would be ¿Cuánta mantequilla tienes?
So, why doesn't cuesta refer to the subject of the sentence? Basically, why does cuesta apply to the verb and not the noun, and why does that make cuesta masculine?
Costar is a verb and verbs get conjugated. They don't change for gender. The subject here is "la mantequilla", a singular 3rd person, so the conjugational form is cuesta.
Saying that cuánto refers to cuesta is a bit misleading. Cuánto is a pronoun here, being the direct object of costar ("It costs this much money"), and Spanish pronouns generally take on the masculine form.
In "¿Cuánta mantequilla tienes?" the question word cuánta is functioning as an adjective, describing the amount of butter. Since the associated noun, mantequilla, is singular-feminine, the adjective will also be in its singular-feminine form.
In "¿Cuánto cuesta la mantequilla?" the question word cuánto is not associated with a noun anymore - it's a pronoun here. We're not asking about "how much butter", but just "how much".
Mae, you could think of it as being masculine because it's agreeing with (the understood) dinero. ¿Cuánto (dinero) cuesta la mantequilla? How much (money) does the butter cost?
In reference the cost
And again "how much for the butter" is incorrect!!! This is spoken English.
It's not a complete sentence, though. A proper sentence needs a conjugated verb.
I wrote 'how much is the cost of butter?' and DL did not accept. Can someone tell me why?
This is not how you express the price of something in English. And it's farther away from the original Spanish sentence, where cuesta is indeed a verb form.
You could say "What is the price of the butter?" if you want to use a noun. In that case, the closest Spanish translation would be "¿Cuál es el precio de la mantequilla?"