For a sacrament to be valid, the matter and form ought to be performed according to the proper ritual, along with the due intention on the part of the minister of the sacrament.
The Church teaches very unequivocally that for the valid conferring of the sacraments, the minister must have the intention of doing at least what the Church does. This is laid down with great emphasis by the Council of Trent (sess. VII, On the Sacraments in General, Canon XI).
In the first scenario, a priest omitting deliberately the formula of absolution might be an indication of the Priest not intending to do what the Church does. If that were the case, not only would this invalidate the sacrament, but also on the account of the absence of the correct formula, which is the form of the sacrament.
If the penitent is aware of the omission, they should request for the absolution with the right formula. The Priest would be offending gravely.
In the second case, the priest unintentionally forgetting the formula of absolution, and not through carelessness, and especially if this is one-off, there would be no indication of absence of the intention on the Priest's part, so long as during the administration of that sacrament, the Priest intended to do what the Church does.
Again the penitent if aware, should request for the absolution.
Please see:
The Catechism does not speak directly to a priest forgetting to give absolution, but there are several statements that would make one think forgetfulness does not determine a failure to receive forgiveness for sin. Here is a sampling of some of the relevant references:
1468 Supports my initial statement above
“The whole power of the sacrament of Penance consists in restoring us to God's grace and joining us with him in an intimate friendship.” [Roman Catechism, II, V, 18] Reconciliation with God is thus the purpose and effect of this sacrament. For those who receive the sacrament of Penance with contrite heart and religious disposition, reconciliation “is usually followed by peace and serenity of conscience with strong spiritual consolation.” [Council of Trent (1551): DS 1674] Indeed the sacrament of Reconciliation with God brings about a true “spiritual resurrection,” restoration of the dignity and blessings of the life of the children of God, of which the most precious is friendship with God. [Cf. Lk 15:32]
In 1441, the Church points out only God forgives sin so the forgetfulness of it's ordained minister, priest or bishop, would not negate forgiveness
Only God forgives sins. [Cf. Mk 2:7] Since he is the Son of God, Jesus says of himself, “The Son of man has authority on earth to forgive sins” and exercises this divine power: “Your sins are forgiven.” [Mk 2:5, 10; Lk 7:48] Further, by virtue of his divine authority he gives this power to men to exercise in his name. [Cf. Jn 20:21-23]
1461 points out that it is the bishops who are the primary ministers of this sacrament
Since Christ entrusted to his apostles the ministry of reconciliation, [Cf. In 20:23; 2 Cor 5:18] bishops who are their successors, and priests, the bishops' collaborators, continue to exercise this ministry. Indeed bishops and priests, by virtue of the sacrament of Holy Orders, have the power to forgive all sins “in the name of the Father, and of the Son, and of the Holy Spirit.”
1464 points out that priests must make it available
Priests must encourage the faithful to come to the sacrament of Penance and must make themselves available to celebrate this sacrament each time Christians reasonably ask for it. [Cf. CIC, can. 486; CCEO, can. 735; PO 13.]