Q:

When and how should a layperson declare their achievements?

I have on occasion seen commenters here and elsewhere who declare their achievements, such as being a sotāpanna. These comments are downvoted, so they do not appear to be appreciated.
If comments like these show up on public forums then casual visitors may themselves see that the path can be followed, that people living today have found that the teachings work, and may themselves be inspired to study the Dhamma. That would be a good possible outcome from such comments.
So is it considered wrong to write such declarations publically (at least if one is not a monk) and when would be the appropriate time and place to make declarations of achievements?

A:

...then if he wants he may state about himself: 'Hell is ended; animal wombs are ended; the state of the hungry shades is ended; states of deprivation, destitution, the bad bourns are ended! I am a stream-winner, steadfast, never again destined for states of woe, headed for self-awakening!'

"I am a stream-winner!", and as for people like Nyom Alexander, at least you can help them with frog-pills. Be aware that a fully awakened person neither lives nor could live in a household, other than the Noble Beggars.
As for a monk, it's not good to do so (toward laypeople) and if doing such as a deliberated lie it is even a reason to fall out of the community.
It may be good to add that a stream-enterer would seldom be able to teach and lead much and as most are still just a householder, give less inspiration for those having real faith. 
But it's a great achievement and a great place for mudita with such or sometimes for much karuna, like in Nyom Alexanders situation, not even knowing the Dhamma yet and believing to be awakened. Thats really much place of huge pity and the reality that beings are heirs of their actions, not really to be helped.
See a Noble Ones answer for more details; and keep such people high and protected without the need that they would need to tell.
(not given for trade, exchange, stacks... but for your way out) See? ;-)

A:

There are many reasons one might do it here are examples from the canon;

Now at that time the wanderer Sañjaya was residing in Rajagaha with a
  large company of wanderers — 250 in all. And at that time Sariputta
  and Moggallana were practicing the holy life under Sañjaya. They had
  made this agreement: Whoever attains the Deathless first will inform
  the other.
  ...
  Then Sariputta the wanderer went to Moggallana the wanderer. Moggallana the wanderer saw him coming from afar and, on seeing him, said, "Bright are your faculties, my friend; pure your complexion, and clear. Could it be that you have attained the Deathless?"
"Yes, my friend, I have attained the Deathless. "

or as has already been linked to above;

...then if he wants he may state about himself: 'Hell is ended; animal wombs are ended; the state of the hungry shades is ended; states of deprivation, destitution, the bad bourns are ended! I am a stream-winner, steadfast, never again destined for states of woe, headed for self-awakening!'

Furthermore Vinaya lists exceptional conditions when even monks can blamelessly proclaim attainment to laypeople;

pācittiya 8 "yo pana bhikkhu anupasampannassa uttarimanussadhammaṃ
  āroceyya, bhūtasmiṃ pācittiyaṃ."
Not to announce to a layman a realisation that has been achieved. If a
  bhikkhu announces to a layman or to a sāmaṇera, a realisation
  partaking with a jhāna nature or with a stage of ariyā, and this
  realisation has genuinely been achieved, he commits a pācittiya.
On the other hand, a bhikkhu who makes such a declaration, while
  knowing it to be false, commits the pārājika 4. A bhikkhu must avoid
  making his attainments known, even to other bhikkhus. Apart from four
  exceptions when they can do so, ariyās never unveil their
  realisations:
Under a violent threat. Undergoing an oppressive and virulent lack of
  respect. A t the time of passing away. To reveal it to his preceptor
  or to a fellow bhikkhu who does a similar practice.

There are more examples from commentaries in example in case of Ariyupavadantaraya according to VSM one might inquire about the status of another by asking 'Have you gained a footing in this Dhamma & Discipline to which a bhikkhu answers by informing of the realization of sotapatti fruition, whereafter the other Bhikkhu informs him of reviling a noble person and informing about one's own level of attainment. Or take another case where the daughter's status can be inferred from her speaking of Anathapindika as her younger brother in the Dhamma.
As i see it these type of claims are mostly vain and baseless products of delusioned imagination. However there is nothing inherently wrong with the act itself and one can do so if one feels thus inclined. If one is really attained to the supposed level then it is certainly nothing one should feel a need to conceal or be ashamed of but i see no need to scream from the rooftops nor to randomly bring up either.
In short i think the Vinaya sums it up;
 - if people are excessively disrepectful and abusive
 - under threat of violence
 - at the time of passing away
 - to reveal it to his preceptor or to a fellow bhikkhu who does a similar practice. 
For this last one i take it to mean that one can tell people who are doing a similar practice ie a friend who also wants to achieve the highest release, such as in the case of Sariputta and Moggalanna as an example and this can be easily understood to be potentially beneficial as is evident by it leading up to the attainment of Moggalanna.

A:

When and how should a layperson...
I wouldn't say "should" (i.e. are "required" to), of course. But "may" (i.e. are "allowed" to)?
I think that monks "must not" i.e. they're required not to, by the vinaya:

It's a most serious offence to lie about an attainment (i.e. to declare that one has one, knowing that claim to be false)
It's also a lesser offence for a monk to declare any super-mundane attainment to a lay-person, whether that's true or false.

The reason for the latter rule was that lay-people would prefer (perhaps to get more merit) to give to monks with super-mundane attainments, which would disadvantage other monks. This latter rule or reasoning maybe doesn't apply to laypeople.
I think that the former rule results in monks being reluctant to declare an attainment even amongst themselves.
Anyway you might keep that in mind: if the vinaya is good rules for monks then maybe it's good or instructive for lay-people too, and lay-people might want to emulate the good conduct of monks to whatever extent they can, on the other hand the vinaya isn't always and directly applicable, and perhaps it's good and necessary that laypeople do some things which monks are forbidden to.
casual visitors may themselves see that the path can be followed
My personal experience says that's true -- i.e. my seeing "sotāpanna" or something like that, on one of the user profiles on this forum, help to guide me to learn more about the path (the doctrine), for example the "four stages of enlightenment" and the "fetters" -- at a time when I hadn't previously been introduced to the Pali canon.
Or (I can't find a reference now, but someone posted on this site once to say that) one of the effects of repeating "nam myoho renge kyo" is that people who don't know might ask, "what are you saying?" -- so maybe it's like that a bit.
I sympathise with this answer too.
people living today have found that the teachings work
For that to work, the person making the claim maybe needs to be credible.
and may themselves be inspired to study the Dhamma
For that to work, the person making the claim maybe needs to be admirable.
I'm reminded of a joke or story from long ago, I don't remember who it's attributed to (Gandhi, perhaps)

"Have you ever thought of becoming a Christian?"
"Well if you mean 'Christian' like your Christ -- I don't have the courage to. But if you mean 'Christian' like you, I wouldn't want to be."

Anyway the theory, that it may inspire others, isn't very convincing if the exemplar isn't inspirational.
You could even argue the opposite, that a "bad" example might put people off ("No, if that's what being a Buddhist is, I wouldn't want to be like that."). Let's hope that people will find true Dhamma anyway.
So is it considered wrong to write such declarations publically
I'd like to answer instead, about making a declaration privately.
I was told, in private,

Don't let anyone tell you that you're not enlightened.

To me that phrase has several meanings:

If you tell me, "You're not enlightened", then why should I care what you think? You don't know me, I haven't met you, I don't even know if you know what enlightenment is.
There's an English proverb: "Don't let the bastards grind you down", it's a bit like that -- friendly advice.
"Don't let them tell you" doesn't have to mean disputing with them, though -- see SN 7.2.
Some people may try to control you by "putting you down", by saying things like ...
-- "You're poor, but I can make you rich"
-- "You're oppressed and disadvantaged, but I can make you free and powerful"
... or ...
-- "You haven't done enough for me, you need to do more"
Some people might be susceptible to, become victims to, that kind of message.
I suppose that "cults" might form that way.
Or some people get into "abusive" relationships when they needn't.
Anyway, I take the message as advice to not accept that.
If I don't allow you to tell me that I'm not enlightened, part of the reason is, "Don't tell me because I will be the judge of that" -- i.e. that I'm more able than you are to know whether I'm enlightened, I have the experience and knowledge and should trust my judgement rather than yours.
For example if I experience a fetter then perhaps I'll know that experience (and you won't).
So maybe I'm the one, the only one, who should be telling myself, "You're not enlightened."
But the advice said, "Don't let anyone tell you that you're not enlightened", that "anyone" is "me too".
So according to the advice I mustn't let myself tell myself, "You're not enlightened, e.g. for this and that reason."
To "not let" that, I have to change the fact or the view.
So that's good advice -- "don't see yourself as unenlightened, and if you do then don't let yourself remain unenlightened."
Given that "putting oneself in the place of another" is orthodox, I also don't think I should tell anyone else that they're not enlightened.
That doesn't mean I should surrender all judgement -- I might still decide that a lie is a lie, or that a good deed is a good deed.
And actually the Buddha probably did assess the enlightenment of everyone (using the "divine eye").
Even so, if someone "declares their achievement publicly", I'm not sure I should make that any concern of mine. If I must assess it (which I should if I consider the speech as doctrine) then, as quoted here, "Those monks’ speech, monks, is not to be rejoiced over, not to be scorned at."
There's probably Mahayana doctrine too, that people have "buddha-nature", and that the word "enlightenment" is empty.
Perhaps there's some disagreement or misunderstanding among Buddhists of what a word like "stream entry" even means. You might think it's impossible to misunderstand, that there are whole books about the definition. But I think that the suttas tell of people attaining stream-entry just from hearing a dhamma talk -- conversely,

For instance, 'stream-entry' according to some Mahayana is synonymous with the First Bhumi or becoming an Arya being. That is, it is marked by the direct perception of emptiness while in meditative equipoise. I don't believe this is the Theravada account at all.

Given that stream entry is associated with the eradication of identity-view, I'm not sure it's sensible to view it as "their enlightenment" or "their achievements".
Maybe it's sensible to view is as a property of the dhamma -- i.e. that stream-entry is a consequence of the dhamma's being well-expounded, Svākkhāto bhagavatā dhammo.
I think one of the troubles some people have is thinking that enlightenment is something else i.e., "There's me, here -- and enlightenment is somewhere else, unattainable" (and thus it's kind of a craving, instead of being a wholesome desire). So, "you're not unenlightened" might help get over that.
If you're going to have a teacher maybe they should teach you how to be good and to be better (and less so someone who would teach you that you're bad).
Also a statement like "I'm enlightened (and you're not)" might be understood as a conceit -- and if that's helpful then good ...

Conceit is one of those qualities we all have — and it's a slippery friend. There are times when it's useful, as in that passage where Ananda teaches a nun that we practice to overcome conceit and yet we have to use conceit in the practice. The example he gives is that when you hear of someone who has put an end to suffering, has made it all the way to the goal, you can reflect, "That person is a human being; I'm a human being. That person can do it; so can I." To that extent, you need conceit in the practice. If you believe that you can't do the practice, or if it seems way beyond you, you end up giving up, you set your sights low. And as we all know, you never hit higher than you aim. So to that extent, conceit is helpful.

... otherwise maybe don't fuss about it.

Also I'm not sure its right to call stream-entry an "achievement".
Perhaps it's a process, or the beginning of a process, towards becoming more enlightened.
The suttas talk about enlightenment as an achievement ("there is no more left to be done"), but I believe that means a full or complete enlightenment -- which maybe isn't what you were talking about since you tagged the question stream-entry.

