Ditto excels at one thing in particular: scouting. Ditto allows its user to know exactly what moveset an opponent has without having to do any guesswork. This can be extremely valuable because several Pokemon can run multiple varied move sets and different roles. Determining a moveset is crucial to discovering what role a Pokemon plays in its team, and therefore how to defeat said team.
Ditto also does marginally well in countering sweepers by using their own stats and movesets against them. Dragon-types are particularly susceptible because they are weak to their own STAB attacks. If Ditto can get the jump on a Dragon-type sweeper, it can often take it out in short order even if you take boosting moves into account as Ditto copies stat boosts as well.
The problem with Ditto is that it spends one turn as itself because it needs to use Transform to adopt another Pokemon's stats. This means that any Pokemon that can outspeed it (which is several) can hit it with a super-effective Fighting move before it can Transform and possibly faint it before it gets started.
To use Ditto in competitive battles, you need support. This can come in the form of Wish, which can heal it in case it survives the initial hit; Reflect, which halves all physical damage; Light Screen, which halves all special damage; or any combination of the above or more.
Barring any support, leading with Ditto almost inevitably requires that you have its Hidden Ability, Imposter. Imposter allows Ditto to Transform as soon as it's sent out, without having to wait for you to spend a turn. This is crucial if you want to run Ditto as a lead or without support because that one turn is absolutely vital.
Also, note that while Ditto will copy stats including temporary stat boosts, Ditto will not copy base HP nor will it copy HP EVs. So, you will want to put at least 252 HP EVs if you're fielding a Ditto.