If the host is receiving packets from a server, these packets have a destination IP address of the host and it is first received by the gateway present in the host network. Now the gateway checks the ARP, indexes using the IP address of the host to find the MAC address of the host, now it changes the link-layer (4-layer internet model) destination address (MAC address) to that of the host MAC address found from the ARP table. Then it forwards the frame to the layer 2 switch. But my question is, how can it forward the frame to the layer 2 switch since the frame has a destination MAC address of the host, not the MAC address of the switch. obviously gateway cannot forward the packet directly to the host since they are not connected and all packets have to go through the switch to reach the destination host. So what am I missing? have I understood something wrongly?
Assuming that the link layer between router and host is indeed a MAC-based link layer, and with layer-2 switching through a switch, then, yes, you are correct about how the router looks up the IP address, sees that this subnet is directly connected to one of its interfaces, and so it looks up the ARP table and sets the MAC address to be the MAC address for the host. Note, though, that the IP address lookup is layer 3 logic, whereas the router than passes it to the network interface card for that interface connected to the subnet, and the layer 2 logic is what finds the correct MAC address for the host.
Your confusion I think is because you are thinking that the router needs to send the MAC frame to the switch by setting the MAC address to the MAC address of the switch. No, the router just needs to know the interface to send out the MAC frame, and the MAC address of the host. There is no additional "routing" done at that time that needs the MAC address of the switch in order to make that the "destination". The layer 2 destination is the host, and the host MAC address is the right one to use.
So then the router spits out the layer 2 frame on that interface, and the switch will receive it and look at the MAC address. The switch also maintains an ARP table mapping the known MAC addresses to ports, and can then pass the frame on, out of the right port for the host.
ps. You may wonder, what is the purpose of the MAC address of the switch itself? This is for cases where the switch itself is the end-point, e.g., the switch supports configuration over a http interface. But that is different from the cases where the switch is just passing through the layer 2 frames to the intended destination, out of one of its ports
A router doesn't change MAC addresses. It routes packets. On reception, it strips the MAC frame off the packet, it is of no interest. Then the router consults its routing table, determines the next hop and passes the packet to it.
"Passing the packet" on a MAC-based link layer requires a MAC frame to encapsulate the packet. Among other details, the MAC frame requires a destination MAC, which is the MAC of the next hop (determined by ARP for IPv4 or NDP for IPv6).
Not all networks a router connects to are MAC-based. The ubiquitous Ethernet or Wi-Fi are but e.g. a serial link isn't.