Can two Catholics who are married by a justice of the peace be denied the eucharist and what do they need to do to be able to receive the eucharist again?
In short: yes.
However the priest needs to be 100% sure that the civilly married couple has not rectified the situation otherwise he could cause scandal by refusing someone who has every right to receive.
The Code of Canon Law establishes that “Those upon whom the penalty of excommunication or interdict has been imposed or declared, and others who obstinately persist in manifest grave sin, are not to be admitted to Holy Communion” (can. 915).
Marriage is considered a “public act” by the Church and thus such actions are to be considered inherently “manifest.” Marriage and sexuality are considered grave matter by the Church. A Catholic who has entered into an invalid marriage is considered to be in a state of manifest grave sin.
Naturally, pastoral prudence would strongly suggest the avoidance of instances of public denial of Holy Communion. Pastors must strive to explain to the individuals in question the problem with their situation in such a way that they would be able to understand why they shouldn’t receive communion. In those situations, however, in which these precautionary measures have not had an effect or in which they were not possible, the minister of Communion must refuse to distribute it to those who are canonically ineligible.
In order to be eligible to receive communion the couple needs to have their marriage “blessed” by the Church. Essentially they will provide their sacramental records to their parish priest and exchange their marriage vows in the presence of the priest and the Church will accept their vows.