The starting material is a chiral compound and its chirality is present at the carbon atom.
In the presence of an acid, the compound is protonated with an acid to form its protonated form and then the protonated aldehyde undergoes keto-enol tautomerism to form its enol as follows:

Keto-enol tautomerism
In the enol form chirality is absent at -carbon atom and it is a planar structure, In acid medium keto to enol and enol to keto tautomerism undergoes frequently. Enol form abstracts a proton from the acid and followed by elimination of proton is as shown:
In this process enol formed behaves as a nucleophile and acid behaves like an electrophile.
In this mechanism proton approaches from above and below the plane of the enol form which is as shown:

Mechanism of reaction in the presence of an acid
In this reaction, starting material is a pure (R) chiral compound but at the end of the reaction, both (R) and (S) forms are present in the reaction mixture. Thus, a racemic mixture is formed.
In presence of a base, the compound is deprotonated with a base to form its enolate ion which is as shown:
In the enol form chirality is absent at -carbon atom and it is a planar structure.

Resonance form
In this process, the enolate ion behaves as a nucleophile and water behaves like an electrophile. In this mechanism, water approaches from above and below the plane of the enol form which as shown:

Approach of water from above and below the plane
In this reaction, starting material is a pure (R) chiral compound but at the end of the reaction, both (R) and (S) forms are present in the reaction mixture. Thus, a racemic mixture is obtained.