Given two words, transform the first one into the second
The algorithm is wrong and can't be fixed.
It's not dynamic programming, it's greedy: it iterates over the strings once and decides immediately which operation to perform. Consider some test cases:
                 case 1            case 2            partial read

string 1:        abcde             abcde             abc..
string 2:        abxde             abxcd             abx..

optimal          replace c         insert x          ?
strategy         by x              delete e

Both cases are identical in the first three characters, yet the operations to perform are different. They depend on characters not yet read.
Any algorithm that does not take into consideration the full picture before making a single descision must fail at least one of those test cases. Yours fails the second.
Brute force
The naive way to overcome this problem is a brute force algorithm. Evaluate all possible sequences of operations (insertions, deletions, replacements). When all input was read, output the best sequence.
Dynamic programming
Dynamic programming starts out similar to brute force and evaluates all possible operations, but whenever it finds that two sequences of operations yield the same intermediate result, it keeps (and evaluates further) only one of them.