The action had been taken by a group called the Campaign to Separate Church and State which argued that the payment breached the constitutional prohibition of the endowment of religion.
Initially the action was taken against the state but the Catholic Church regarded it as so important that the four Catholic archbishops successfully applied to be joined as co-defendants.
In a reserved judgment Mr Costello said that by paying the salaries of chaplains the state was having regard to the rights of parents regarding the religious formation of their children. The payment did not mean that the state itself was endowing the religion they professed.
The state and the archbishops were allowed costs against the Campaign but a stay was allowed on the order of costs in the event of an appeal.
The Campaign has expressed disappointment at the outcome. A spokesman claimed it meant that every secondary school in the country would be entitled to have a chaplain at the state's expense.
He also expressed surprise that the costs were awarded to the archbishops. "We end up paying the costs of defendants we did not want, since our action was against the state," he said.
It is estimated that the costs will be around Pounds 50,000.
The Campaign also has to pay the costs of its own legal team which was headed by a former attorney general, Mr John Rodgers.
The Campaign itself has very little funds. It is basically a small secular ginger group comprising academics and intellectuals who try to raise issues related to the state's responsibilities to its citizens, particularly those of no religious belief.
According to a constitutional expert Gerry White, from Trinity College Dublin, the high court ruling removes one of the constitutional doubts surrounding the "integrated curriculum", that is the holistic approach to education whereby religious values permeate the entire curriculum.
He says that in the light of Mr Justice Costello's decision one cannot argue that such a system amounts to an unconstitutional endowment of religion.
The Campaign had proposed a second legal action, this time over the integrated curriculum which is provided for in the official rules for primary schools, but that is now unlikely to go ahead.
A further effect of the judgment is that it probably paves the way for the introduction of religion as an examination subject in the state's Leaving Certificate examination.
The current education minister Niamh Bhreathnach favours its introduction but had been advised legally to await the outcome of the high court action. Paradoxically, that action may have strengthened rather than weakened the position of the churches in Irish education.