When a host wants to send something to a host in a different LAN, the sending host can tell it is sending to a different LAN because its own network and mask are configured in it. Based on that knowledge, it knows it needs to send the traffic to its configured gateway (router). It may have the MAC address of the gateway in its ARP cache, or it may not. If it doesn't, it needs to use ARP to resolve the gateway's IP address to its MAC address.
Once it has the gateway's MAC address, it can encapsulate the IP packet in the ethernet frame, and send the frame to the gateway. The router will get the frame and strip the frame off the packet. It will inspect the packet and look to see if it has a route to the destination IP address in its routing table. The routing table could be populated in multiple ways, including routing protocols like OSPF.
If the router cannot find a route to the destination, it drops the packet. If it does find a route, it will switch the packet to the outbound interface where it will apply a new layer-2 frame for the outbound interface. This may involve ARP, again.
When the second router gets the frame from the first router, it will repeat the process that the first router did. It will send the frame it created out the LAN interface toward the receiving host.
Switches will learn the MAC address of devices connected to the switch ports as those devices send traffic through the port. The switch updates its MAC address table. Switches don't have forwarding tables the way routers do, but they will send a frame to a port where the destination MAC address is known, and they will flood frames with unknown destination MAC addresses to all ports.
Routers get route information to populate their forwarding tables from multiple sources. The most common source is from the directly connected networks. Routes can be statically configured, or they can be learned via a routing protocol (RIP, OSPF, IS-IS, BGP, etc.). Traffic without a route in the forwarding table will be dropped.
If your router already knows the route to the destination (directly connected, statically configured, or dynamically learned from a routing protocol) it will forward it out the proper interface toward the destination. If it has not already learned the route to the destination, the traffic will be dropped.
If you have new questions beyond clarification, you need to ask a new question, but this question is really too broad to get into more detail than what I have outlined above.