A (layer-2) switch doesn't care at all about the IP networks you run through it.
however, no normal traffic can occur between two nodes on two different networks.
That is correct. Different IP networks require a router/gateway in between, even if they actually run in the same layer-2 segment.
how does a Layer-2 switch prevent normal traffic between say two different networks that were configured using IP addresses and subnet masks which are layer3 I assume?
Actually, it doesn't. A layer-2 switch forwards frames based on their destination MAC address. At the same time, it learns which nodes are located on each switch port by examining each frame's source MAC address (self-learning bridge). That switch does nothing to stop any connected nodes from communicating with each other (unless it's a managed switch with ACLs, MAC address filtering, various snooping options etc.).
IP nodes from different IP subnets cannot communicate with each other without using a gateway. They don't even try. (There are various methods to trick the nodes into believing they are sending packets to a gateway when they actually don't, but I won't dive into that here. By the book, a gateway is required. In fact, you could even define additional subnets as being on-link = local - just talk out of interface x - so each host would be its own gateway. But obviously you'd need to do that on all hosts.)
Of course, there's nothing stopping a node from adding an IP address from the other subnet to its interface and start communicating with those nodes. That's why multiple IP subnets within the same L2 segment/VLAN are very rarely used. It's usually a pain to manage and there's no actual security gain. If you'd like to add security you need to use separate switches or separate VLANs.
IP nodes need to route packets - all nodes do, not just gateways. The destination IP address is matched to the entries in the local routing table and the entry best matching the destination (longest prefix match) determines the local interface and the next-hop gateway. In the simplest case, there's only a single local interface and a single default route/gateway, matching all destinations.
When the destination matches a locally attached subnet, the packet is sent directly to the destination (after determining the MAC address via ARP for IPv4). However, when there's no default route and no specific route to the destination either, the packet in question has nowhere to be sent and it is dropped.
Should not all nodes can communicate with each other based on the fact that they all exist in a MAC-based world.
Nodes connected to a simple switch (or a VLAN for that matter) can communicate on the data link layer (L2).
IP nodes can only communicate directly if they are connected to the same L2 segment and share an IP subnet. Everything else requires a gateway.