I know this is something small but I am genuinely curious about it. Are questions like "How would you like your coffee?" grammatically correct? Isn't it supposed to be "How would you like your coffee to be?"? Are both of these correct? Could you explain the reason and the rule behind it, please? Thank you so much.
Yes, it is grammatically correct, though it is a shortening of "How would you like your coffee prepared?" or "How would you like me to make your coffee?" or the example you provided. They are all correct, but the one you wrote sounds a bit less natural, in my opinion.
Due to the context of the situation, the prepared part is implied and often omitted by the speaker for the sake of brevity. The listener knows that the other person intends to make the coffee.
It is similar to "What type of coffee do you want?" Again, the prepared part is implied and is unnecessary. A native speaker would understand, whichever version you decide to use.