We separate networks like this when we don't want certain devices to talk to each other and when we want to reduce unnecessary network traffic and congestion and improve security.
We split up Ethernet networks for several reasons.
One is to control broadcast traffic. Particularly embedded devices may struggle if the broadcast traffic rises too high.
Another is that Ethernet requires a loop-free topology, that is fine in a small network, but as the network gets larger it gets more and more inefficient.
Another is security, while it is possible to do filtering on layer 2 Ethernet traffic, it's generally easier and more convenient to do it on an IP device. It's also easier to prevent/mitigate issues like one device hijacking traffic intended for another.
Is the router necessary to divide the network like this?
There are two distinct but related concepts.
The first is the Layer 2 domain. That is the group of devices that can send Ethernet* packets to each other directly over a physical or virtual Ethernet network.
The second is the IP subnet, this defines what hosts the IP stack will assume are "on link" by default and send IP packets to directly, rather than trying to send them to a router.
Most of the time we keep a 1:1 mapping between Layer 2 domains and IP subnets. That is not to say there are never reasons to put multiple IP subnets on the same Layer 2 domain or to split a subnet between Layer 2 domains, but it's something that should be carefully considered before proceeding.
What if we removed the router but kept the IP addressing?
Then by default, if the IP stack is behaving in the expected manner, the hosts should be unable to exchange IPv4 unicast traffic.
Note that this is NOT the same thing as saying they would be unable to exchange traffic at all. IPv6, IPX, Netbeui etc are all completely independent of the IPv4 addresses you set. IPv4 broadcast and multicast traffic may also pass between the hosts.
You could make specific hosts able to exchange IPv4 unicast packets, by adding explicit entries to their routing tables to mark the other hosts as on-link and/or adding secondary IP addresses. You could also deploy a "one-armed router", which routes between multiple subnets on the same L2 link layer.
Having multiple subnets on one link and trying to restrict traffic between them is likely to lead to a false sense of security. You test with your ipv4 unicast pings and everything seems to be in order, but then either a malicious actor gets sufficient privileges to reconfigure the network stack on one of the hosts, or they discover can perform their malicious actions over a protocol other than IPv4 unicast.
* In theory other multipoint link layers exist, in practice in the real world it's very rare to see anything other than Ethernet or Wi-Fi which are similar enough for these purposes.