The plot accelerates when a warrior from one tribe falls in love with a girl from the other tribe. Turns out the two tribes are being kept separate for genetic purposes because the union of the two will create a super race, which the people controlling the spaceship don't want. I read this in the 1970s.
Sounds like Captive Universe (1969) by Harry Harrison.
The synopsis on the Wikipedia page indicates that the main character is Chimal, a member of one of two tribes living within an isolated valley, and separated from one another by a river. There's a strict ban on intermarriage between the two villages, and it's believed that the river is guarded by Coatlicue, a two-headed serpent goddess. Chimal later escapes his village, and discovers that 'Coatlicue' is a machine, and that both tribes are living aboard a huge generation ship.
Chimal is a young Aztec tribesman living in an isolated valley which was sealed off from the rest of the world in ages past by a massive earthquake. Unlike the rest of his people, who are content with the way things are, he shows more interest in what lies outside the valley, and in asking questions that no one can answer. Indeed, he is altogether brighter; more intelligent than others, which often gets him into trouble, and makes him seem "unusual" to his peers.
The valley is home to two villages, one on each side of the river that flows through the middle, Quilapa (Chimal's village) and Zaachila, both of which share a temple staffed with priests who perform holy duties and interpret the laws of the Gods. This includes a ban on intermarriage between the two villages, which is strictly observed. Despite this, Chimal's mother conceived Chimal by a man from Zaachila, a fact she manages to keep secret for many years.
After Chimal refuses to marry his intended bride, and the chief priest dies of a stroke following the ensuing argument, he is arrested by the priests and condemned to sacrificial death. The Gods, angry at the sacrilege, cause the sun to fail to rise at dawn, and in the panic he is rescued by his mother, who takes his place in the cell where he is held. Before he leaves, she reveals who his real father was.
Escaping, he attempts to find a way out of the valley, while avoiding being hunted by the priests, and Coatlicue, the dreaded two-headed serpent-Goddess who stalks the land at night and kills those who foolishly wander near the river past sunset.
When he finally manages to break through the blockage at the end of the valley, Chimal finds himself in a series of many strange tunnels. He is also surprised when he meets Coatlicue, whom he followed in, in a deactivated state, and thus harmless. Travelling on, he finally meets a stranger, a woman called Watchman Steel; forcing her to lead him on, he ends up meeting more.
After initial misunderstandings, Chimal meets the Master Observer, who hails him as the "First Arriver"; he then learns the secret of the conspiracy which has been perpetrated against his people for centuries. The valley is merely the central cavity of a huge generation ship. The Aztecs are its passengers, tended by the ship's crew in the caverns, the Observers, on a centuries-long flight to Proxima Centauri, the nearest star to our sun.
Five hundred years previously, "The Great Designer", an Earth dictator, converted the asteroid Eros into a generation starship, spinning along its axis for gravity, and sent it on its journey. Because of the enormous distance involved, and the relatively slow speed it could attain, it would be the descendants of the original passengers who would arrive. To preserve order over the centuries, the passengers were split into two distinct groups, with each group genetically engineered for low intelligence in a different way, and given the hierarchical, self-sufficient and order-loving Aztec culture. The Observers were similarly programmed, and given a monastic culture to watch over the ship and the Aztecs. On Arrival Day, the two Aztec groups would be allowed to breed together, removing the genetically programmed recessive traits and producing highly intelligent offspring able to colonise the new system.
When he is shown the control center of the ship, however, Chimal realises there is a major problem. The Observers, too rigid in their thinking to understand the planetary observations, have over-ridden the flight plan and passed Proxima Centauri. On attempting to explain their mistake to them, he is denounced and hunted as a heretic. After pursuit through the ship, he initiates the Arrival program that breaks the barrier between the two Aztec communities and releases them from the valley section of the ship, and the Observers have no choice but to accept that Arrival Day has come. The book ends with the ship due to arrive at Centauri in decades, and Chimal anticipating the day when he will, soon, have equals to talk to.
You can peruse a Google Books preview of the book here.