Were they justified by hearing the gospel, or because they believed what they heard? That's the point. The doing has no power to justify. Only the believing part has the power to secure justification. Believing does that all by itself. That's Paul's point.
Only obedience has the power to secure justification, as without it faith is dead.
Paul teaches this principle clearly, as it takes the divine formula of believing in the heart and confessing with your mouth, to produce a divine result.
We can not disregard the principle of how faith works, which is the corresponding act of obedience, in which we do what we hear, that will cause faith to produce a divine result.
20 And suddenly, a woman who had a flow of blood for twelve years came from behind and touched the hem of His garment. 21 For she said to herself, “If only I may touch His garment, I shall be made well.” 22 But Jesus turned around, and when He saw her He said, “Be of good cheer, daughter; your faith has made you well.” And the woman was made well from that hour. Matthew 9:20-22
Without the action of her faith, by touching the hem of His Garment, this woman would not have been healed.
Let's look at another perspective of this same story.
But as He went, the multitudes thronged Him. 43 Now a woman, having a flow of blood for twelve years, who had spent all her livelihood on physicians and could not be healed by any, 44 came from behind and touched the border of His garment. And immediately her flow of blood stopped.
And Jesus said, “Who touched Me?”
When all denied it, Peter and those with him said, “Master, the multitudes throng and press You, and You say, ‘Who touched Me?’”
But Jesus said, “Somebody touched Me, for I perceived power going out from Me.” 47 Now when the woman saw that she was not hidden, she came trembling; and falling down before Him, she declared to Him in the presence of all the people the reason she had touched Him and how she was healed immediately. Luke 8:42-47
Many people were touching Him, but it was the woman who believed in heart, If only I may touch His garment, I shall be made well... and acted with faith/obedience that was granted a divine result.
Likewise Paul teaches this principle concerning salvation by faith.
8 But what does it say? “The word is near you, in your mouth and in your heart” (that is, the word of faith which we preach): 9 that if you confess with your mouth the Lord Jesus and believe in your heart that God has raised Him from the dead, you will be saved. 10 For with the heart one believes unto righteousness, and with the mouth confession is made unto salvation. 11 For the Scripture says, “Whoever believes on Him will not be put to shame.”12 For there is no distinction between Jew and Greek, for the same Lord over all is rich to all who call upon Him. 13 For “whoever calls on the name of the Lord shall be saved.”
Romans 10:8-13
The message of faith that Paul preached: believe and confess.
"Believing all by itself" is not the message of faith Paul preached.
JLB