The source said the killing was carried out by an 18-year-old Chechen, who was then shot and killed by police near the scene in Conflans-Sainte-Honorine, northwest of Paris.
Police said the victim was 47-year-old history teacher Samuel Paty, who had shown his pupils some cartoons of the Prophet Mohammed as part of a class discussion on freedom of expression — a lesson that had prompted complaints from parents.
Two of the suspect's brothers and his grandparents were initially detained by police for questioning.
The judicial source told AFP Saturday that five more people had been detained, including the parents of a child at the school and friends of the suspect.
According to the source, the parents had signalled their disagreement with the teacher's decision to show the cartoons.
The attack came as a trial is in progress over the January 2015 massacre at the offices of the Charlie Hebdo satirical magazine, which had published caricatures of the prophet Mohammed that unleashed a wave of anger across the Islamic world.
The magazine republished the cartoons in the run-up to the trial in September and last month a young Pakistani man wounded two people with a meat cleaver outside its former offices.
Identification documents found on the suspect showed he was an 18-year-old born in Moscow but from Russia's southern region of Chechnya.
The attacker shouted “Allahu Akbar” (“God is greatest”) as police confronted him, a cry often heard in jihadist attacks, a police source said.
There had been no previous indication that he was a potential radical, a source close to the investigation said.
French anti-terror prosecutors said they were treating the assault as “a murder linked to a terrorist organisation”.
Police said they were investigating a tweet posted from an account — since shut down — that showed a picture of the teacher's head.
It was unclear whether the message, which contained a threat against Macron — describing him as “the leader of the infidels” — had been posted by the attacker, they said.
(article continues below)
See also on The Local:
The killing bore the hallmarks of “an Islamist terrorist attack”, Macron said as he visited the scene.
Visibly moved, the president said that “the entire nation” stood ready to defend teachers and that “obscurantism will not win”.
His Elysee Palace said Saturday that a “national tribute” would be held in Paty's honour, without setting a date.
EU chief Ursula von der Leyen expressed her condolences to the teacher's family and the French people.
“My thoughts are also with teachers, in France and across Europe. Without them, there are no citizens. Without them, there is no democracy,” she tweeted in French.
'Super friendly and kind'
At the school, parents and teachers alike paid tribute to Paty, who was said to have been in his 40s, widely liked and himself a father.
“According to my son, he was super nice, super friendly, super kind,” a parent, Nordine Chaouadi, told AFP.
“I saw him (the teacher) today, he came to my class to see our teacher. It's shocking that I won't see him again,” said Tiago, a student in sixth grade.
The teacher “simply said to the Muslim children: 'Leave, I don't want it to hurt your feelings.' That's what my son told me,” the parent said.
Sources said that one of those detained was a father who had posted a video on social media expressing shock that cartoons showing the prophet “naked” had been shown in his daughter's class.
Rodrigo Arenas, head of the FCPE association of the parents of students, said that a complaint had been received from a “very agitated” father.
But he said the teacher had asked Muslim students if they wanted to leave the classroom before showing the cartoons.
Police had arrived at the scene after receiving a call about a suspicious individual loitering near the school, a police source said.
They discovered the dead man and soon spotted the suspect, armed with a blade, who threatened the officers as they tried to arrest him.
They opened fire, severely injuring him, and he later died of the wounds.